8

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.

Omtechguy
  • 3,321
  • 7
  • 37
  • 71
  • 1
    Possible duplicate of [Access docker container from host using containers name](https://stackoverflow.com/questions/37242217/access-docker-container-from-host-using-containers-name) – David Maze Sep 05 '19 at 17:37

1 Answers1

3

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

Yasen
  • 4,241
  • 1
  • 16
  • 25
  • 1
    So i understand that there is no native solution for that ? – Omtechguy Sep 08 '19 at 10:52
  • 1
    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. – Blake Neal May 04 '20 at 13:39
  • AWS has it's own DNS: `Route 53` – Yasen May 06 '20 at 12:57