Automagic discover docker containers with dnsdock and CoreOs
Note: This is the second part of How I develop in PHP with CoreOS and Docker. I recommend reading that post first to get a better view on this post.
Docker is an awesome tool for developing all kinds of applications in an isolated environment. Altough I came across some minor issues and flaws.
- Run only one container on a specific port
- Manually add a container’ IP and domainname in
I managed to fix these flaws with dnsdock.
dnsdock is a DNS service discovery for Docker containers written in golang.
In other words, everytime I start a container the
dnsdock service, which is also a container, creates a new dns record pointing to the IP of this container.
This is awesome! Why? Because I don’t need configure a specific port-forwarding to the host machine AND domainnames are added automaticaly.
It’s also possible to add one or more aliases to a specific container.
How to setup
Since I’m using the Docker in CoreOs setup from my previous post - How I develop in PHP with CoreOS and Docker - all we need to do is the following:
- Autostart the
dnsdockservice with CoreOs
- Add nameserver entry in
/etc/resolver/dockerto lookup in the
- Edit the
Vagrantfile, so CoreOS accept packets for other IPs
- Add a custom route for all the container IPs to the CoreOS IP
- Optional: Add alias domain(s) to your docker command or docker-compose.yml
dnsdock with CoreOS
user-data file in
coreos-vagrant and add the following under the
Add nameserver entry in
This way Mac OS X will do a
dns lookup for all domains ending with
It’s also possible to change this to a custom development domain, example:
Edit the Vagrantfile
This will enable promiscuity for some private network interfaces and accept all incoming packages.
Add a custom route for all the container IPs to the CoreOS IP
Make sure Mac OS X routes all container traffic to the CoreOS VM.
Vagrant will re-provision the CoreOS settings and startup
dnsdock on boot.
Note: Sometimes I need to do this twice, because the
user_data changes were not applied properly.
Check dnsdock services
http://dnsdock.docker/services to see all discovered services.
You can access a running container on
containername.imagename.docker as hostname.
You can add a docker environment variable
DNSDOCK_ALIAS to a container.
This allows you to access this container on:
The same can be done in a
There is so much more you can achieve with this
Thanks for reading
Feel free to leave a comment if you have remarks or like this post