Here is one more useful parameter external_links
that didn't mentioned in this thread:
external_links:
- redis_1
- project_db_1:mysql
- project_db_2:postgresql
- {CONTAINER}:{ALIAS}
It is close to extra_hosts
:
extra_hosts:
- "somehost:127.0.0.1"
- "otherhost:127.0.0.2"
- {HOSTNAME}:{IP}
but allow to set dynamic container IPs
In addition of it aliases may be added at network level. Here is two answers [ 1, 2 ] how to add alias to network, but I want to add extra info:
If you didn't set network in docker file you may use default
to add alias to default network:
services:
db:
networks:
default:
aliases:
- database
- postgres
Thanks to this answer