Show HN: mDNS name resolution for Docker container names

npmjs.com

2 points by chfritz a day ago

I always wanted this: an easy way to reach "resolve docker container by name" -- e.g., to reach web servers running in Docker containers on my dev machine. Of course, I could export ports from all these containers, try to keep them out of each others hair on the host, and then use http://localhost:PORT. But why go through all that trouble? These containers already expose their respective ports on their own IP (e.g., 172.24.0.5:8123), so all I need is a convenient way to find them.

mdns-docker allows you do to, e.g., "ping my-container.docker.local", where it will find the IP of a running container whose name fuzzily matches the host. The way it does it is by running a local mDNS service that listens to `*.docker.local` requests, finding a running container whose name contains the request (here: "my-container"), getting that container's local IP address, and responding to the mDNS query with that IP.

Example: Start a ClickHouse service (as an example) `docker run --rm --name myclicky clickhouse:25.7` and then open `http://myclick.docker.local:8123" to open the built-in dashboard -- no port mapping required!

If you haven't played with mDNS yet, you've been missing a lot of fun. It's easy to use and the possibilities to make your life easier are endless. It's also what Spotify and chromecast use for local device discovery.