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 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.

  • Docker 1.12 Swarm: TLS changes
  • How to transfer a environment variable into a dockerfile
  • What is the difference between Docker Hub Registery and
  • How to connect to docker VM (MobyLinux) from windows shell?
  • boot2docker / docker “Error. image library/.:latest not found”
  • Motivation for putting Docker containers inside an AWS EC2 instance
  • 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 & docker run:

    docker run -d  --link kanban_redis:kanban_redis -p 80:80 -e KANBAN_SERVER_HOSTNAME="http://localhost"  -e KANBAN_GITLAB_URL=""  -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

    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?

  • Clustering Docker containers behind load-balancers for HA
  • Weird terminal formatting on Windows
  • How can I create a docker volume container in specific directory?
  • Connecting to mongo container using node getting MongoError
  • Ansible task timeout max length
  • add new GPG key detailed in Docker installation
  • 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.