Add option to remove service name as default alias on networks
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 38.2k
- Forks
- 5.8k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 55
Description
(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_1andproject2_database_1should be known by onshared_networkare the custom aliases provided. - From within
project1:- The DNS for
databaseshould always point toproject1_database_1over theproject1_app_internalnetwork - The DNS for
project1-databaseshould always point toproject1_database_1over theshared_networknetwork - The DNS for
project2-databaseshould always point toproject2_database_1over theshared_networknetwork
- The DNS for
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Docker Compose network configuration and the documented service-name alias behavior described in the issue. Compare service-level and network-level scope against the two Compose examples; done means the chosen option omits the service-name alias on the shared network while preserving explicit aliases and local service-name resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100