Mac OS X, Vagrant, Docker, Nginx, Node – how do ports play together?

I have a simple nginx, node.js setup that I want to migrate into the Vagrant, Docker world. I’m not sure how to handle IPs and ports.

My goal is it to see my Hello World in the Browser, best case on port 80, simply by calling my host http://example.com.

  • How to send node.js logs to Cloudwatch Logs from Elastic Beanstalk Docker application?
  • docker build on a private git repo containing the Dockerfile?
  • Unable to push windows docker image to Artifactory
  • IBM Bluemix Binding a VPN Service to a container
  • Docker not mapping port using gunicorn
  • What are the best practices for tagging Docker Hub versions
  • UPDATE
    I found the solution myself – I created a simple boilerplate here:
    https://github.com/ezmilhouse/docker
    Feel free to go on from here.

    app.js

    var app = express();
    
    app.route('*').all(function(req, res) {
      res.send('Hello World!');
    });
    
    app.listen(2000)
    

    nginx.conf

    upstream example.com {
    
      # using the vagrant private network IP (I guess?)
      # using the node port
      server 192.168.33.10:2000
    
    }
    
    server {
    
      # ports nginx server is listen to
      listen 80;
      listen 443;
    
      location / {
    
        # upstream proxy
        proxy_pass http://example.com;
    
        # ...
    
      }
    
    }
    

    Vagrantfile.proxy

    Vagrant.configure("2") do |config|
    
      config.vm.box = "ubuntu/trusty64"
      config.vm.provision "docker"
    
      # settimg a hostname that matches nginx upstream (I guess?)
      config.vm.hostname = "example.com"
    
      # setting a private network IP, node.js and nginx run on this IP (i guess?)
      config.vm.network "private_network", ip: "192.168.33.10"
    
    end
    

    Vagrantfile

      Vagrant.configure("2") do |config|
    
        config.vm.define "nginx" do |app|
          # forward the nginx port (I guess?)
          app.vm.network "forwarded_port", guest: 80, host: 80
          app.vm.provider "docker" do |d|
            d.build_dir  = "./docker/nginx"
            d.vagrant_vagrantfile = "./Vagrantfile.proxy"
          end
        end
    
        config.vm.define "node" do |app|
          # forward the node port (I guess?)
          app.vm.network "forwarded_port", guest: 2000, host: 2000
          app.vm.provider "docker" do |d|
            d.build_dir  = "./docker/node"
            d.vagrant_vagrantfile = "./Vagrantfile.proxy"
          end
        end
    
      end
    

    /nginx/Dockerfile

    # ...
    EXPOSE ["80"]
    

    /node/Dockerfile

    # ...
    EXPOSE ["2000"]
    

    Mac OS X /etc/hosts

    192.168.33.10 example.com
    

    I was expecting to call http://192.168.33.10 in the browser to see my Hello World via nginx and http://192.168.33.10:2000 to see the node instance. Therefore the host example.com does not work either.

    What do I do wrong?

  • Docker-Compose Issue with container name
  • ECS or EB for a single-container application with Docker?
  • Use Xcode with Docker (cross-compiling)
  • How to bind a port when using docker-py to create a service? [duplicate]
  • How to run a Shiny docker container on Alpine Linux?
  • Docker : initial installation script fails (ubuntu 13.04 , kernel 3.8+)
  • One Solution collect form web for “Mac OS X, Vagrant, Docker, Nginx, Node – how do ports play together?”

    I created the fork and made pull request to your repo.

    The main idea: do not use provisioning for docker containers.

    More information your can find in this article

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