13

I am using docker-compose and docker. everything works great. but the only way to access a service from the host machine is by http://localhost:port. i would like to be able to access by using the container name like: http://elastic:9020.

It works well inside the docker. if one container needs to access another i can use the http://elastic:9020 but not from the Host. Of Course that i am exposing the ports and using port mapping and it works using localhost as i said. Docker

UPDATE: I was looking for a native solution without the needs of installing DNS Server or updating the .host file.

1

1 Answer 1

4

There is an OSS project aimed for resolving Docker's hostnames:

DPS :: DNS Proxy Server

DPS is a end user(developers, Server Administrators) DNS server tool to develop systems with docker solving docker containers hostnames.

Github repo: mageddo/dns-proxy-server

Main features:

  • Solve hostnames from local configuration database
  • Solve hostnames from docker containers using docker hostname option or HOSTNAMES env
  • Solve hostnames from a list of configured DNS servers(as a proxy) if no answer of two above
  • Solve hostnames using wildcards
  • Graphic interface to Create/List/Update/Delete A/CNAME records
  • Solve host machine IP using host.docker hostname
  • Access container by it’s container name / service name
  • Specify from which network solve container IP

Usage:

docker run --rm --hostname dns.mageddo \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /etc/resolv.conf:/etc/resolv.conf \ defreitas/dns-proxy-server

Sign up to request clarification or add additional context in comments.

3 Comments

So i understand that there is no native solution for that ?
I wish there was an easy answer... However you slice it, you need to modify or replace how your DNS server handles and parses Docker containers. I got this tool running on a CentOS 8 VM instance with multiple Docker containers running different cross-dependent SaaSs (Spring Boot apps, Keycloak, etc) and it worked basically out-of-the-box. That being said, I would LOVE to see documentation on how this would work (or a good solution on how to make addressing work in general) in a production environment like AWS.
AWS has it's own DNS: Route 53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.