Viper
Viper

Reputation: 1377

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. I have the following 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.

Upvotes: 0

Views: 961

Answers (1)

winwiz1
winwiz1

Reputation: 3164

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

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. The capital 'P' means: do publish all exposed ports. 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.

Upvotes: 1

Related Questions