Container names in Docker Compose must be unique to prevent conflicts and ensure proper container management. Duplicating container names makes the configuration invalid, and Docker Compose will not be able to start any containers if this occurs.
This rule is not fixable automatically, as it requires user intervention to resolve the conflict by specifying unique container names for each service.
- Rule Name: no-duplicate-container-names
- Type: error
- Category: security
- Severity: critical
- Fixable: false
services:
web:
image: image
container_name: my_container
db:
image: image
container_name: my_container
services:
web:
image: image
container_name: web_container
db:
image: image
container_name: db_container
When container_name
is specified in Docker Compose, it assigns a custom name to the container, which can override the
default naming scheme. While this can be useful for easily identifying containers, duplicate names can cause Docker
Compose to fail to start services, leading to a non-functional configuration.
This rule ensures that container names across services are unique to prevent conflicts in the Docker networking layer, which can disrupt the container management process and network connections.
This rule was introduced in Docker-Compose-Linter 1.0.0.