Container names in Docker Compose must match the regular expression pattern [a-zA-Z0-9][a-zA-Z0-9_.-]+ to avoid
invalid names and ensure compliance with Docker naming conventions.
- Rule Name: service-container-name-regex
- Type: error
- Category: security
- Severity: critical
- Fixable: false
services:
web:
image: image
container_name: "my-app@123"services:
web:
image: image
container_name: "my-app-123"This rule ensures that container names in Docker Compose follow the required format defined by the regular expression
[a-zA-Z0-9][a-zA-Z0-9_.-]+. If a container name contains invalid characters, it can lead to errors when Docker tries
to run the services. This rule identifies invalid names and prevents configuration errors.
Container names should only consist of letters, numbers, underscores (_), hyphens (-), and periods (.). Any other
characters, such as @, make the configuration invalid. This rule prevents such issues by ensuring that all container
names are properly formatted according to Docker's naming conventions.
This rule was introduced in v1.0.0.