Docker Desktop on Windowsでnode.jsのコマンドを実行する

環境

  • Docker Desktop for Windows 4.0.0
  • Node.js 14系

実行方法(うまくいくもの)

node:14のイメージを使用する。

docker run --rm -it -v <ホストの絶対パス>:/home/node/app -w /home/node/app node:14 <コマンド>

実行方法(失敗することがあるもの)

node:14-alpineのイメージで「npx create-react-app」をしたらエラーが出た。根本原因は不明。

$ docker run --rm -it -v <ホストの絶対パス>/:/home/node/app -w /home/node/app node:14-alpine npx create-react-app 20210912-react-ts-app --template typescript
npx: installed 67 in 14.328s

Creating a new React app in /home/node/app/20210912-react-ts-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...

yarn add v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.15.2.tgz: 140593871818056:error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac:../deps/openssl/openssl/ssl/record/ssl3_record.c:677:
".
info If you think this is a bug, please open a bug report with the information provided in "/home/node/app/20210912-react-ts-app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
^C
Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template-typescript --cwd /home/node/app/20210912-react-ts-app has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Done.