Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.46 KB

File metadata and controls

46 lines (33 loc) · 1.46 KB

Service Container Name Regex Rule

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

Problematic Code Example

services:
  web:
    image: image
    container_name: "my-app@123"

Correct Code Example

services:
  web:
    image: image
    container_name: "my-app-123"

Rule Details and Rationale

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.

Version

This rule was introduced in v1.0.0.

References