How to combine a Nginx and a NodeJS Docker container
I’ve a nodejs container which hosts my backend and I have a nginx container which is hosting my Angular.
They are both working fine. I’m able to visit my nodeJS container and I’m able to visit my Nginx-container.
The problem is there seems to be no connection between the containers.
The nginx container is only hosting the /dist folder which contains the angular but nothing from the NodeJS.
Do you have to edit the
/etc/nginx/nginx.conf or the
--link command for this?
I read somewhere that your nodejs and nginx would bind automatically.
My backend is running on 8888, frontend on 8080.
nginx dockerfile (The npm install etc are already performed in jenkins)
FROM nginx COPY dist /usr/share/nginx/html/dist FROM node
RUN mkdir -p /usr/src/test WORKDIR /usr/src/test COPY node_modules /usr/src/test/ COPY server.js /usr/src/test/ EXPOSE 8080 CMD [ "node", "server.js" ]
I start them by performing:
docker run -d -p 80:80 --name "app" localhost:5000/test/nginx-image:1 docker run -d -p 8888:8888 --name "app-" localhost:5000/test/nodejs-image:1
One Solution collect form web for “How to combine a Nginx and a NodeJS Docker container”
You need to link the containers. Also when containera talks to containerb it will use http://container-name not http://localhost so your code should account for this. You will notice when you use link that inside the container docker will add an entry in the hosts file to this effect. Use environment variables so you can make the domain name to which you will make requests flexible. And pass this environment variables when you run the container
Make sure u expose the right ports between containers