3

I want to set up a small web server running several web apps, like OpenProject and GitLab, as well as OpenLDAP for user management. In order to encapsulate the single applications, docker should be applied.

Now I have read about several possibilies on how to allow the apps to talk to each other by using their hostnames (e.g. web app to slapd). Most solutions use DNS servers, either running on the docker host like here, or in a separate docker container.

However reading the docker user guide, I also found that custom docker networks also allow name resolution inbetween the containers in the network.

Naturally I would prefer the second approach using docker networks, since it requires less tools and thus configuration. However I'm a little bit confused in what way now docker networks and custom DNS servers are different. Are there any details I overlook?


Added minor clarification in last paragraph.

2
  • If you use Linux or Unix (including OS X), setting up a DNS server with dnsmasq is a cinch. Dec 17, 2015 at 16:14
  • @MariusMatutiae: Thanks for this hint, I already had a look at dnsmasq. If the server was for private purposes only, I would do so, in oder to learn it. However in it also requires additonal configuration, and I would prever a solution as easy as possible.
    – empwilli
    Dec 19, 2015 at 11:59

1 Answer 1

1

I am currently doing something similar. I use the Docker linking feature. By linking two container together you can set a DN under which the linked container is accessible. I personally use docker-compose for a better config than just plain commands. You can even set up networks an give containers access to that. But every access happens over the docker created DNs as the IP's of the container can change on restart.

As an example how I use it for owncloud and nginx as an ssl offloading proxy.

version: '2'
services:
  nginx:
    container_name: nginx_proxy
    image: nginx
    links:
      - owncloud:owncloud
    networks:
      - owncloud_web
    ports:
      - 80:80
      - 443:443
    volumes:
      - ...

owncloud:
  container_name: owncloud
  links:
    - owncloud_db:postgresql
  networks:
    - gitlab_web
  volumes:
    - ...

owncloud_db:
  container_name: owncloud_db
  image: postgres:9.4
  networks:
    - owncloud_db
  volumes:
    - ...

networks:
  owncloud_web:
  owncloud_db:

With that nginx can access owncloud under owncloud while owncloud can access it's database under postgresql. I set up separate networks so nginx can't access the database directly.

When using an external DNS-server you have to know the ip addresses of the containers which can change at any restart. Even the complete subnet may change. So either you have to implement a dynamic DNS system or hope the IP's won't change.

When using docker internals you don't have to run any additional service and don't ever have to rely on IP addresses.

1
  • I use a custom docker network in order for communication between the containers now. However, I found that I have to use an additionally use a small dnsmasq server, since I want to access some of my containers via name (eg. my exim container) from scripts. Here I use a small self-written daemon and the docker event mechanism.
    – empwilli
    Mar 20, 2016 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .