【发布时间】:2019-05-24 14:50:12
【问题描述】:
我有一个想要 dockerize 的项目。我在我的计算机上运行npm install 和npm build 没有问题,但是当我使用 Docker 构建时会出现一些问题。
Docker 输出:
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.
卡在这里:
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"]
我已经用其他 dockerfiles 做了这个,但结果是一样的。
package.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"
]
}
【问题讨论】:
-
删除
--silent并检查日志。 -
@rdas 它没有去那个地方,因为它卡在第 5 阶段,那就是 npm install
-
我运行你的代码,一切正常。你使用的是什么 Docker 版本?
-
你用的是什么操作系统?
-
Offtopic 但你的包中已经有 react-srcripts 所以你试图在你的 docker 中安装 2.1.8 和 3.0.1。你可以通过在你的包中增加版本来完全避免它。
标签: reactjs docker dockerfile