我正在为调试React应用程序构建一个Docker镜像,使用单独的Dockerfile
FROM node:11-alpine
COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY public/ ./public/
COPY src/ ./src/
EXPOSE 3000
CMD yarn run start
使用
package.json
。{
"name": "yarn-start-in-kubernetes",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-scripts": "2.1.3",
"babel-loader": "8.0.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
当使用
docker run
时,启动开发服务器的效果符合预期。升级至... "react-scripts": "2.1.3",
"babel-loader": "8.0.4"
导致安装程序失效,因为开发服务器终止:
> docker run dev
yarn run v1.15.2
$ react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.2/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Done in 2.72s.
docker run
在 Done in ...
后返回。
我想在调试镜像中使用更高版本,而这些版本在生产中也能正常工作。如何让它们在调试镜像中运行?
这些版本似乎不会影响 Docker 外部的开发服务器的运行,即 yarn start
可以同时与两个版本组合使用。