[英]Run create-react-app in production mode in Docker
I'm trying to run a create-react-app project in production mode inside a docker container.我正在尝试在 docker 容器内以生产模式运行 create-react-app 项目。 I have the following Dockerfile.
我有以下 Dockerfile。
FROM node:10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
RUN npm install serve
RUN yarn global add serve
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
EXPOSE 5000
CMD serve -s build
Each time I run this container, I get "INFO: Accepting connections at http://localhost:5000"
but the nothing shows on port 5000. Any suggestions would be appreciated.每次运行此容器时,我都会收到
"INFO: Accepting connections at http://localhost:5000"
,但端口 5000 上没有任何显示。任何建议将不胜感激。
You are running a webserver inside your container.您正在容器内运行网络服务器。 It listens on a port.
它监听一个端口。 You need to know the port and then publish it.
您需要知道端口然后发布它。
For example, you discovered that your webserver listens on port 5000. Then you can publish the port by using command-line argument docker run -p 5000:5000
例如,您发现您的网络服务器侦听端口 5000。然后您可以使用命令行参数
docker run -p 5000:5000
发布该端口
EXPOSE
doesn't publish the port, it merely records some meta information inside the container and this information can be used by docker run -P
. EXPOSE
不发布端口,它只是记录容器内部的一些元信息,这些信息可以被docker run -P
使用。 The capital 'P'
means: do publish all exposed ports.大写
'P'
表示:发布所有暴露的端口。 This is rarely done so EXPOSE
is used more like a hint for users of your DOCKERFILE
regarding the docker run -p XXXX:YYYY
port publishing you expect them to do.很少这样做,因此
EXPOSE
是对DOCKERFILE
用户关于docker run -p XXXX:YYYY
端口发布的提示,您希望他们这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.