In my docker-compose file there is a need for several containers to know the hostname of a specific container, including this specific container.
Links will not work, si
extra_hosts
did the trick for me.
extra_hosts:
- "hostname:127.0.0.1"
From the docker-compose docs:
extra_hosts Add hostname mappings. Use the same values as the docker client --add-host parameter.
extra_hosts: - "somehost:162.242.195.82" - "otherhost:50.31.209.229" An entry with the ip address and hostname will be created in /etc/hosts inside containers for this service, e.g:
162.242.195.82 somehost 50.31.209.229 otherhost