Deploy node application whit docker and nginx

I am looking into a lot of content on the internet how to solve the following situation; many blogs are incomplete and don’t get right to the point. Let’s see who can help me.

I have a web application written in react, so we are in the context of the node.

So once tested, locally or on a server we write the Dockerfile for production named as

Many blogs put both the app source code and the nginx processes in this file. You will then have the following file:

FROM node:16-alpine as builder


COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

FROM nginx:1.22-alpine as nginx

COPY --from=builder /app/build /usr/share/nginx/html 

COPY /nginx.conf /etc/nginx/conf.d/default.conf

I believe it can also be done differently,ie create two distinct docker images and start them in the docker-compose file. I found some examples but not very reliable, although I think it is the right way, as it gives you more control for each process. So if by any chance someone wants to write the steps that would be great.

Returning to our problem, let’s write the docker-compose for an image that will be provided by the docker file written above.

version: '3.8'
    container_name: my-website
      context: .
      - "80:80"
    restart: unless-stopped

Once this is done, we create the docker image, which will then be pushed into the docker-hub(private).I leave out the commands. We get to the problem: we create a project on DigitalOcean, we create a droplet, we make all the most suitable configurations, we also buy a domain on some supplier for example, we set the dns for the droplet. We enter with the ssh key, we pull our image from the docker hub and finally we have to start it. Now my question is if a container opens on a door with the flag -p 8080:80 for example; to find my webapp I have to write instead of just writing How is this problem solved?

PS: I didn’t put many commands or all processes to do for security.

I inform you that I have also read this article, but I do not like the initial phase because it does not use the build command.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I am a DigitalOcean customer since February 2021. I have a Ubuntu machine having Nginx and a Node.js application which I wish to Dockerize.

This is the current architecture

What do you advise me to do? What are the steps to correctly refer my domain to the container?

Bobby Iliev
Site Moderator
Site Moderator badge
July 21, 2022

Hi there,

Your setup looks actually correct. Are there any other services running on port 80 that could be causing the problem?

You can check this with:

netstat -plant | grep 80

It is possible that if you have Nginx already installed on your server itself, then the Docker container would not be able to use port 80 so you will have to stop the Nginx service on the host, and then restart the container.

If this is not the case, what is the exact error that you get when you try to access



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up