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.

  • Meteor mupx ssl configuration is not working, still routing to port 80
  • Docker return codes from background commands
  • Docker containers - DNS issue
  • Minikube: how to ssh into the VM?
  • Docker mysql image: periodic access denied for root
  • Docker abbreviation for --name run option
  • 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
    

  • Simple Docker Concept
  • An error occurred trying to connect - docker when not using sudo
  • How to pull image from custom docker registry with golang?
  • Docker build “Could not resolve 'archive.ubuntu.com'” apt-get fails to install anything
  • Docker or Docker for AWS and Deployment on AWS EC2
  • Docker, no IPAddress in docker inspect
  • 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.