dockerチュートリアルでnpmエラー


Dockerの公式ドキュメント

Docker document Quickstart part2でエラーが発生
$ docker build --tag bulletinboard:1.0 .の部分で

Step 4/7 : RUN npm install
 ---> Running in 1a42d2b3c5dd
npm notice
npm notice New patch version of npm available! 7.0.3 -> 7.0.8
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.8>
npm notice Run `npm install -g [email protected]` to update!
npm notice
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/vue reason: Unexpected token � in JSON at position 70253

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-11-05T12_02_36_331Z-debug.log

やったこと1

Node.jsとnpmを直接インストール
インストール方法
インストールあと以下のサイトで設定
Node.jsのPath(パス)を確認する方法【初心者向け】
あとコントロールパネル>システム>アドバンスドシステム設定(左下)>環境変数>システム変数のpathを編集してC:\Program Files\nodejs\を追加(自動でできてるかも)

やったこと2

bulletin-board-appファイル内のpackage-lock.jsonファイルを削除して
$ docker build --tag bulletinboard:1.0 .を実行

まだエラー出ていたので、dockerfileの5行目にRUN npm cache verify



FROM node:current-slim

WORKDIR /usr/src/app
COPY package.json .
RUN npm cache verify
RUN npm install 

EXPOSE 8080
CMD [ "npm", "start" ]

COPY . .

なんとなくうまくいった?

$ docker build --tag bulletinboard:1.0 .
Sending build context to Docker daemon  12.03MB
Step 1/8 : FROM node:current-slim
 ---> 922b09b21278
Step 2/8 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 5d3d82eda8ed
Step 3/8 : COPY package.json .
 ---> Using cache
 ---> 7cc831630440
Step 4/8 : RUN npm cache verify
 ---> Using cache
 ---> 54aab39eb76b
Step 5/8 : RUN npm install
 ---> Using cache
 ---> b6e782bc92e7
Step 6/8 : EXPOSE 8080
 ---> Using cache
 ---> baf0c121f375
Step 7/8 : CMD [ "npm", "start" ]
 ---> Using cache
 ---> 5fcb2b27e8f0
Step 8/8 : COPY . .
 ---> b02d075c5110
Successfully built b02d075c5110
Successfully tagged bulletinboard:1.0
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

最後の
SECURITY WARNING:~~~~は無視

結論

もっとNode.jsやらの知識を身に着けてからの方がいい