Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

508
Visualizações
How to resolve docker host names (/etc/hosts) in containers

how is it possible to resolve names defined in Docker host's /etc/hosts in containers? Containers running in my Docker host can resolve public names (e.g. www.ibm.com) so Docker dns is working fine. I would like to resolve names from Docker hosts's (e.g. 127.17.0.1 smtp) from containers.

My final goal is to connect to services running in Docker host (e.g. smtp server) from containers. I know I can use the Docker Host IP (127.17.0.1) from containers, but I thought that Docker would have used the Docker host /etc/hosts to build containers's resolve files as well.

I am even quite sure I have seen this working a while ago... but I could be wrong.

Any thoughts?

Giovanni

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Check out the --add-host flag for the docker command: https://docs.docker.com/engine/reference/run/#managing-etchosts

$ docker run --add-host="smtp:127.17.0.1" container command

In Docker, /etc/hosts cannot be overwritten or modified at runtime (security feature). You need to use Docker's API, in this case --add-host to modify the file.

For docker-compose, use the extra_hosts option.

For the whole "connect to services running in host" problem, see the discussion in this GitHub issue: https://github.com/docker/docker/issues/1143.

The common approach for this problem is to use --add-host with Docker's gateway address for the host, e.g. --add-host="dockerhost:172.17.42.1". Check the issue above for some scripts that find the correct IP and start your containers.

over 4 years ago · Santiago Trujillo Relatório

0

You can setup on host simple DNS server, and in container setup /etc/resolve.conf to Docker host DNS server.

For example in dnsmasq you can add addn-hosts=/etc/hosts to config file. So container, by using Docker host DNS server, will be able to resolve hosts /etc/hosts.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda