Skip to content

Docker container names to DNS records that can be resolved locally

Notifications You must be signed in to change notification settings

madebymany/pharod

Repository files navigation

# Pharod

The problem: you have all kinds of things running in Docker containers on your Mac, and to get at them you have to remember which darned ports you got them listening on. Binding to well-known ports works great until you need to work on two projects at once. You wish you could just address your containers with nice hostnames, on the port that is natural for the service in question.

The solution: a daemon that monitors Docker to watch for containers with exposed ports, works out the port number that you want to use, and listens on that port on the next available 127.0.0.0/8 alias (the whole block points back to the loopback device, not just 127.0.0.1). It can then resolve a hostname derived from the container name to that address. The effect:

$ docker run -dP --name redis redis
b58899b0319ca62f2fe5d97e1ea34204f73ce1b419c56c7e29aab8efac227036
$ pharodctl ls
redis.pharod: 127.2.2.1:6379 -> 192.168.64.3:32769

# wait a few seconds for Redis to start...

$ redis-cli -h redis.pharod
redis.pharod:6379> set hello "there"
OK

But we can also run another Redis, and we still don't have to worry about ports:

$ docker run -dP --name redis2 redis
75bc2222924d8321633dd1a974d5b72ea7c8b31e6c59a64f0cacbe06463de76a
$ pharodctl ls
redis.pharod: 127.2.2.1:6379 -> 192.168.64.3:32769
redis2.pharod: 127.2.2.2:6379 -> 192.168.64.3:32770
$ redis-cli -h redis2.pharod
redis2.pharod:6379> get hello
(nil)

Note the second forwarder uses a new loopback IP address. Pharod will only use new addresses when there would be a clash; it uses the same one for many if forwarders can exist on different ports.

At the moment Pharod is built for OS X, particularly in the hostname resolving, but I don't think there's any reason in principle why it wouldn't work on Linux too, as long as you could find some way to hook into system-wide hostname resolving on a per-TLD basis. OS X makes that easy: we just make a config file in /etc/resolver/pharod.

Using

It's currently in our Homebrew repository, so:

$ brew tap madebymany/custom
$ brew install pharod

Then use pharod-start to start it, and pharodctl ls to inspect its state. It requires using dlite or the Docker for Mac beta. Stop it with pharod-stop. It doesn't use launchd because it's quite nice to be able to inspect possible errors on startup like this. Might integrate when it's more mature.

About

Docker container names to DNS records that can be resolved locally

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •