I have several docker containers running web apps. They can be accessed on my network using the IP of the host and the port number i've bound to in the container.

I would like to be able to access the apps via a fqdn, for example, app1.home.com (or home.com/app1 if that is easier).

To achieve this I guess I would need a dhcp and dns server running on my network. I plan to configure dnsmasq. This would allow me to resolve the home.com domain locally.

Then I figure I would need a proxy of some description to route to the specific port. I know this can be achieved with nginx or apache, but I don't know how and it seems a bit over kill. I think HAProxy could be an option, again I dont know how.

TL;DR: How can I address web-apps running in docker containers using a fqdn on my home network?


Just configure your docker host to have several ips, one for each hostname you would like to configure. Then configure dnsmasq to point each ip to a different hostname, site1.home.com->X.X.X.X, site2.home.com->Y.Y.Y.Y. All of these ips will belong to your docker host.

Then start up your containers on the docker host. I use docker swarm with an overlay network, frontended by an nginx reverse proxy. I set up docker containers to belong to this overlay network, and I specify --names for them so the docker overlay network has it's own dns for the nginx reverse proxy to use to point to other containers.

Then I configure nginx to point to the other containers using swarm-based dns depending on the ip used to connect to the docker host. So http://X.X.X.X/ is translated by nginx to point to dns name site1 on the overlay network. nginx will go get the site1 container's webpage and return it to the user. It is a lot of overkill but has huge advantages are that it does this redundantly with little downtime because of rolling updates.

For example: I go to home1.home.com in my browser. This triggers a dns lookup changing home1.home.com to X.X.X.X. I am directed to the docker host's nginx reverse proxy, which gets site1's webpage that is hosted on the internal overlay network, based on the ip I used to connect to the docker host. It then presents the webpage to me.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.