(Copied from https://forums.docker.com/t/add-option-to-remove-service-name-as-default-alias-on-networks/106172 after I realized this was a compose-specific request)
I am facing an issue where two separate docker compose projects sharing a common externally defined docker network would encounter DNS name collisions when both projects have a service with the same name.
Example Setup:
project1/docker-compose.yml:
version: '3'
networks:
app_internal:
driver: bridge
shared:
external:
name: shared_network
services:
database:
...
networks:
app_internal:
shared:
aliases:
- project1-database
project2/docker-compose.yml:
version: '3'
networks:
app_internal:
driver: bridge
shared:
external:
name: shared_network
services:
database:
...
networks:
app_internal:
shared:
aliases:
- project2-database
Problem:
shared_network is an externally created docker network common to both project1 and project2. When I spin both projects up, both the project1_database_1 and project2_database_1 containers are aliased to database on shared_network, in addition to the custom aliases provided.
Making things worse, when I try to communicate with database on other containers in project1 or project2 who are also connected to shared_network, it's a tossup whether I'll be talking with project1_database_1 or project2_database_1 .
Desired Outcome for Example:
- The only aliases
project1_database_1 and project2_database_1 should be known by on shared_network are the custom aliases provided.
- From within
project1:
- The DNS for
database should always point to project1_database_1 over the project1_app_internal network
- The DNS for
project1-database should always point to project1_database_1 over the shared_network network
- The DNS for
project2-database should always point to project2_database_1 over the shared_network network
- Ditto for
project2
Feature Request:
Currently, the problematic behavior occurs because of this interaction in the Docker-compose documentation:
Other containers on the same network can use *either* the service name or this alias to connect to one of the service’s containers. (emphasis mine)
I would like to have an option at either a service level or a network level to tell Docker Compose not to add the service name as an alias when attaching a network.
(Copied from https://forums.docker.com/t/add-option-to-remove-service-name-as-default-alias-on-networks/106172 after I realized this was a compose-specific request)
I am facing an issue where two separate docker compose projects sharing a common externally defined docker network would encounter DNS name collisions when both projects have a service with the same name.
Example Setup:
project1/docker-compose.yml:
project2/docker-compose.yml:
Problem:
shared_networkis an externally created docker network common to bothproject1andproject2. When I spin both projects up, both theproject1_database_1andproject2_database_1containers are aliased todatabaseonshared_network, in addition to the custom aliases provided.Making things worse, when I try to communicate with
databaseon other containers inproject1orproject2who are also connected toshared_network, it's a tossup whether I'll be talking withproject1_database_1orproject2_database_1.Desired Outcome for Example:
project1_database_1andproject2_database_1should be known by onshared_networkare the custom aliases provided.project1:databaseshould always point toproject1_database_1over theproject1_app_internalnetworkproject1-databaseshould always point toproject1_database_1over theshared_networknetworkproject2-databaseshould always point toproject2_database_1over theshared_networknetworkproject2Feature Request:
Currently, the problematic behavior occurs because of this interaction in the Docker-compose documentation:
Other containers on the same network can use *either* the service name or this alias to connect to one of the service’s containers.(emphasis mine)I would like to have an option at either a service level or a network level to tell Docker Compose not to add the service name as an alias when attaching a network.