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
I think the correct answer is from
Aliases can be defined as part of the network declaration for a service. See aliases in Compose file reference for more details on that. – King Chung Huang Apr 24 '17 at 15:18
here is the example from the doc
version: '2'
services:
web:
build: ./web
networks:
- new
worker:
build: ./worker
networks:
- legacy
db:
image: mysql
networks:
new:
aliases:
- database
legacy:
aliases:
- mysql
networks:
new:
legacy:
you can access the db
in this docker-compose, also you can use mysql
to connect this db