Setup subdomains in docker environment

I am running different services in Docker Containers on my Ubuntu server (14.04 Trusty Tahr) at home. My currently Setup at the moment is as following:

  • Jenkins jenkins.slarti
  • Gitlab and leanlabs.io under gitlab.slarti
  • Java Servlet Webserver under servlet.slarti (apache tomcat)
  • “Normal” Webserver under web.slarti (nginx)

These domains are virtualhost’s and I have already setup an nginx proxy.

  • Is there an alternative/workaround for `boot2docker save`?
  • Fedora docker.io seems to not support btrfs
  • MySQL in Docker container
  • How to docker exec to IBM bluemix containers
  • how to make docker bypass the page cache in Mac OS
  • Meteor Up Docker and Graphicsmagick
  • Nginx-proxy docker run:

    docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy
    

    Jenkins docker run:

    docker run -d --name jenkinsci --expose 8080 -e VIRTUAL_HOST=jenkins.slarti -e VIRTUAL_PORT=8080 jenkins
    

    Normal Webserver docker run:

    sudo docker run --name nginx1 -P -d --expose 80 -e VIRTUAL_HOST=web.slarti nginx
    

    Gitlab & leanlabs.io docker run:

    docker run -d  --link kanban_redis:kanban_redis -p 80:80 -e KANBAN_SERVER_HOSTNAME="http://localhost"  -e KANBAN_GITLAB_URL="http://mygitlab.com"  -e  KANBAN_REDIS_ADDR="kanban_redis:6379" --expose 80 -e VIRTUAL_HOST=gitlab.slarti leanlabs/kanban:1.4.0
    

    Apache Tomcat docker run:

    docker run -it --rm -p 8888:8090 -e VIRTUAL_HOST=servlet.slarti tomcat:8.0
    

    I did the setup according to this guide http://blog.florianlopes.io/host-multiple-websites-on-single-host-docker

    Currently I can’t ping web.slarti, servlet.slarti etc. Neither can i reach these domains if i type their url in the browser.

    I can reach Apache Tomcat via slarti:8888 but I want to reach it through servlet.slarti and that fails since i don’t have a DNS setup.

    What do I have to do to reach the subdomains web.slarti, servlet.slarti etc? How do I setup the reverse proxy correctly so I can reach the domains? And how do I have to configure the DNS?

  • Docker(compose) installing nodejs broke npm
  • How to create a virtual cluster using docker on a single node?
  • docker-compose issue with hadoop + hbase setup
  • When to Use Docker's Container Name?
  • Error writing to cgroup parameter cpu.rt_runtime_us
  • how to make docker image ssh enabled
  • One Solution collect form web for “Setup subdomains in docker environment”

    I am not expert on networks. But after reading your post, it appears that you do need a DNS config like this:

    A -> slarti (or IP)
    CNAME jenkins.slarti -> slarti
    CNAME gitlab.slarti -> slarti
    CNAME servlet.slarti -> slarti
    CNAME web.slarti -> slarti
    

    This is what I have done to redirect my subdomains to my Docker containers.

    Without proper DNS configuration, your subdomains can’t be reached.

    With this DNS config, everytime you request gitlab.slarti, you actually reach Nginx, which in turn redirects you to the proper Docker container (if the VIRTUAL_HOST environment variable is configured to gitlab.slarti).

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