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

397
Visualizações
how does docker-compose map my service names into IP addresses?

I have a docker-compose.yml file that I use to run a web application.

version: '3'
services:
  web:
    entrypoint: gunicorn myapp.wsgi:application --bind 0.0.0.0:7000
    ...
  nginx:
    ports:
      # HOST:CONTAINER
      - 80:80
      - 443:443
    ...

Inside my nginx service's container:

$ cat /etc/hosts

127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.144.4   790c0822b887

$ curl http://web:7000

<h1>Bad Request (400)</h1>

$ traceroute web

traceroute to web (192.168.144.3), 30 hops max, 46 byte packets
 1  ec2-user_web_1.ec2-user_default (192.168.144.3)  0.008 ms  0.007 ms  0.006 ms

So I can lookup the web hostname and it's mapped to the IP address 192.168.144.3, but I don't see it in the /etc/hosts file.

How docker-compose specifically set up this container such that curl knows the IP address?

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

0

Docker provides a DNS service (search for “automatic DNS resolution between containers”), and Docker Compose provides a default “user-defined” network that uses it. If you look at /etc/resolv.conf inside your container, it should point at a Docker-private IP addresses which provides hostname resolution for both the general Internet and for other containers.

More specifically in a Docker Compose context, the name of each entry in the services: block is resolvable as a host name by other containers launched from the same docker-compose.yml file. You do not need to set container_name:, hostname:, links:, or networks:; this is all configured automatically for you.

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