Docker 停留在 npm install

beh*_*nam 5 docker reactjs dockerfile

我有一个要 dockerize 的项目。我运行npm install,并npm build与我的计算机上没有任何问题,但它有一些问题,当我建立与码头工人。

码头工人输出:

Sending build context to Docker daemon  56.96MB
Step 1/7 : FROM node:12.2.0-alpine
---> f391dabf9dce
Step 2/7 : WORKDIR /app
---> Using cache
---> b50a8efbf074
Step 3/7 : ENV PATH /app/node_modules/.bin:$PATH
---> Using cache
---> 3358967a13ab
Step 4/7 : COPY package.json /app/package.json
---> Using cache
---> 851ac31a0adb
Step 5/7 : RUN npm install
---> Running in 8cc36a435cec
npm WARN deprecated core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
Run Code Online (Sandbox Code Playgroud)

它卡在这里:

Dockerfile:

# base image
FROM node:12.2.0-alpine

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install react-scripts@3.0.1 -g --silent

# start app
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)

我已经用其他 dockerfiles 做到了这一点,但结果是一样的。

包.json:

{
  "name": "front",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "bootstrap": "^4.3.1",
    "express": "^4.17.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router": "^5.0.0",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
Run Code Online (Sandbox Code Playgroud)

nim*_*199 -4

我遇到过同样的问题。我只等了1个小时就进入下一步了。

编辑:在构建 npm install 时会下载所有软件包,这需要时间,这取决于应用程序的大小,需要多长时间。