javascript - 如何解决 docker 镜像中的 ERR_EMPTY_RESPONSE?
问题描述
我的码头文件:
# Use the official Node.js 10 image.
# https://hub.docker.com/_/node
FROM node:13.12.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
RUN npm install
# RUN npm install react-scripts@3.4.3 -g
# add app
COPY . /app
CMD ["npm", "start"]
我建立:
$ docker build . -t myapp
Sending build context to Docker daemon 2.051MB
Step 1/7 : FROM node:13.12.0-alpine
---> 483343d6c5f5
Step 2/7 : WORKDIR /app
---> Using cache
---> c731f744759f
Step 3/7 : ENV PATH /app/node_modules/.bin:$PATH
---> Using cache
---> e1f5f853c8c6
Step 4/7 : COPY package.json ./
---> Using cache
---> f831911acf6c
Step 5/7 : RUN npm install
---> Using cache
---> c18449857dd2
Step 6/7 : COPY . /app
---> Using cache
---> 4b99412d4725
Step 7/7 : CMD ["npm", "start"]
---> Using cache
---> e565a34838d5
Successfully built e565a34838d5
Successfully tagged myapp:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Win dows Docker host. All files and directories added to build context will have '-r wxr-xr-x' permissions. It is recommended to double check and reset permissions f or sensitive files and directories.
跑:
docker run -p 3000 myapp
> myapp-fe@0.1.0 start /app
> react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.3/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Compiled successfully!
You can now view rugvista-fe in the browser.
Local: http://localhost:3000
On Your Network: http://172.17.0.3:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
访问:http://localhost:3000/ 给出ERR_EMPTY_RESPONSE
我究竟做错了什么?
解决方案
在 npm start 之前将其添加到您的 docker 文件中
EXPOSE 3000/tcp
修改你COPY . /app
的COPY . .
推荐阅读
- vba - 宏循环遍历除前两个之外的所有工作表并将单元格和范围复制到另一个工作簿中
- javascript - Node.js - execFile 抛出未知的产卵
- c# - MSBuild 从命令行失败,但从 Visual Studio cmd 行成功
- sockets - 从 Socket Golang 读取数据
- eclipse-plugin - 获取悬停的 Xtext 元素
- html - AMP-CAROUSEL 标记中缺少强制属性“灯箱”
- java - Java 的正则表达式
- javascript - gauge.js -> 需要在 javascript 上修改 PercentageColors 函数
- python - 使用 pipenv 安装时如何忽略特定包的依赖关系?
- c# - 用 ReactiveUI 依次执行一组命令