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.

  • Pass optional arguments when running a Docker image
  • running tcpreplay with docker and boot2docker
  • Marathon Docker Tasks Failing
  • Ubuntu + Vagrant + docker compose without using Virtualbox
  • VisualVM connection to Tomcat hosted on Docker
  • Docker container not able to access port 5432
  • 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

    Nodejs dockerfile

    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

  • How to interpret this docker registry creation command?
  • Socketplane and Docker : How to connect 2 (or more) physical hosts with each others
  • nginx inside a docker container doesn't add access-control-allow-origin header as per the conf file
  • Access from container to host
  • Docker swarm create command difference
  • Gitlab-CI multi runner start docker container, scripts now work
  • 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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.