To create and recreate our development environment we are using Docker containers that are started and managed using docker-compose. This works fine in most cases. The only hard thing to manage was access to the webserver and other services. This is because a new IP address is assigned to a Docker container each time it is started.
To fix this issue we searched for a DNS solution that would automatically be configured when an new container is started (e.g dnsmasq). We found this solution in docker-gen. This awsome tool has more than only service discovery. But for now we are only using the service discovery part. And of course we are using docker to run that. The docker-dns container created by jderusse does all we need at the moment.
Setup in ubuntu
Configure the local dnsmasq to forward request to 127.0.0.1:54 And listen to interfaces lo and docker0.
sudo vim /etc/NetworkManager/dnsmasq.d/01_docker bind-interfaces interface=lo interface=docker0 server=/docker/127.0.0.1#54 sudo systemctl restart NetworkManager
Run dns-gen and bind port 53 to port 54 of your host
docker run --detach --name dns-gen \ --restart always \ --publish 54:53/udp \ --volume /var/run/docker.sock:/var/run/docker.sock \ jderusse/dns-gen -R
That was all we needed to do to have our project webservers available at webserver.project.docker.