Sign inSign up

alexandreslp/docker-name-resolver

By alexandreslp

•Updated 6 months ago

Docker Name Resolver (DNR) It's a simple way to resolve the Docker container name to it's IP.

Image
Networking
1

1.3K

alexandreslp/docker-name-resolver repository overview

⁠Docker Name Resolver (DNR)

    ____  _   ______  
   / __ \/ | / / __ \ 
  / / / /  |/ / /_/ / 
 / /_/ / /|  / _, _/  
/_____/_/ |_/_/ |_|   

It's a simple way to resolve the Docker container name to its IP using an internal nginx reverse proxy and the special .localhost domain.

When a container my_service is running, DNR will expose it as http://my_service.localhost from your host machine (Linux, Mac or Windows), without changing the host's hosts file or requiring a custom DNS server.

⁠GitHub⁠

⁠Requirements

  • Docker

⁠Tested Systems

  • Ubuntu
    docker run --restart unless-stopped --detach --tty \
      --volume /var/run/docker.sock:/var/run/docker.sock \
      --group-add (stat -c '%g' /var/run/docker.sock) \
      --publish 80:8080 \
      --name dnr alexandreslp/docker-name-resolver
    

⁠Supported Systems

  • Linux, Mac & WSL
    docker run --restart unless-stopped --detach --tty \
      --volume /var/run/docker.sock:/var/run/docker.sock \
      --group-add (stat -c '%g' /var/run/docker.sock) \
      --publish 80:8080 \
      --name dnr alexandreslp/docker-name-resolver
    
  • Windows (Docker Desktop)
    docker run --restart unless-stopped --detach --tty \
      --volume //./pipe/docker_engine:/var/run/docker.sock \
      --publish 80:8080 \
      --name dnr alexandreslp/docker-name-resolver
    

⁠Usage

After starting DNR, any running container will be connected to the DNR network and available as:

http://<container_name>.localhost

You can also see a simple HTML status page with all active routes at:

http://dnr.localhost/

And you can list the routes from the CLI with:

docker exec -it dnr ./dnr list

The list command prints only the fields that matter in a terminal:

  • CONTAINER: the route/container name
  • IP: the IP address in the DNR network
  • PORTS: one or more exposed ports, joined by | (example: 80 | 443)

Sorting defaults to the same as the status table (container name ascending), and can be customized:

# Sort by container name (ascending/descending)
docker exec -it dnr ./dnr list --sort name --order asc
docker exec -it dnr ./dnr list --sort name --order desc

# Sort by IP (ascending/descending)
docker exec -it dnr ./dnr list --sort ip --order asc
docker exec -it dnr ./dnr list --sort ip --order desc

⁠FAQ

  • Problem: Name or service not known
    • Solution: Clear DNS cache sudo apt-get -y install nscd && sudo service nscd restart

Tag summary

Content type

Image

Digest

sha256:5bb551288…

Size

28.5 MB

Last updated

6 months ago

docker pull alexandreslp/docker-name-resolver