【发布时间】:2020-10-14 19:49:25
【问题描述】:
我正在为我的微服务应用程序创建一个 kubernetes 集群。 我正在构建 docker 映像,但由于某种原因,它卡住了@npm install step:
卡在这里:
$ docker build -t karanshreds/client .
Sending build context to Docker daemon 626.2kB
Step 1/7 : FROM node:alpine
---> 3bf5a7d41d77
Step 2/7 : ENV CI=true
---> Running in 3ffe706d12a3
Removing intermediate container 3ffe706d12a3
---> bcd186e89d1b
Step 3/7 : WORKDIR /app
---> Running in 4b68ea73ef58
emoving intermediate container 4b68ea73ef58
---> 2427bc0ae6e8
Step 4/7 : COPY package.json ./
---> 2d26f309fb4d
Step 5/7 : RUN npm install
---> Running in ce5043208676
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated @types/testing-library__dom@7.5.0: This is a stub types definition. testing-library__dom provides its own type definitions, so you do not need this installed.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
Dockerfile
FROM node:alpine
ENV CI=true
WORKDIR /app
COPY package.json ./
RUN npm install
COPY ./ ./
CMD ["npm", "start"]
当我使用 node 而不是 node:alpine 时它可以工作。 但它会创建大小为 1GB+ 的图像。这显然是我不想要的。
#NOTE:以防万一您想知道我的 package.json 文件有什么:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
【问题讨论】:
-
你说你得到一个错误,但我在 docker build 命令的日志中没有看到任何错误,只是一堆关于某些包被弃用的警告,你也应该尝试使用多阶段 docker 构建并实际构建反应应用程序而不是使用开发版本
-
我刚刚编辑了它。你能帮忙吗?
标签: node.js reactjs docker npm kubernetes