Docker
Dockerfiles
Docker Naming
DevOps
Software Development

Dockerfile naming conventions

Codemia Knowledge Hub ·

Name the file Dockerfile when a project builds one image, because that is the name Docker looks for in the build context by default. When a project builds several images, the common convention is Dockerfile.<service-name> (for example Dockerfile.web or Dockerfile.api), passed to docker build with -f. Docker itself imposes no strict naming rules beyond the default.

Why the naming scheme matters

  • Clarity: a descriptive name tells you at once what the file builds.
  • Consistency: the same scheme across projects makes them easier to navigate.
  • Automation: build scripts rely on predictable file names.

The default name: Dockerfile

For simple projects with a single image, keep the default:

 
my-project/
└── Dockerfile

One Dockerfile per service: Dockerfile.<service-name>

For projects with multiple services or containers, use:

 
Dockerfile.<service-name>

The service name should state the image's main purpose, such as Dockerfile.webserver or Dockerfile.database.

Any file not named Dockerfile has to be passed explicitly at build time:

bash
docker build -f Dockerfile.<service-name> -t image_name .

A multi-service application with a web server, a backend API and a database could look like this:

 
1my-app/
2├── Dockerfile.web
3├── Dockerfile.api
4└── Dockerfile.db

New services get their own Dockerfile without renaming existing ones, and team members can tell each file's purpose at a glance.

Versioned, branch and variant Dockerfiles

Versions

For applications that change often, you can add a version:

 
Dockerfile.<service-name>.<version>

The version typically matches the semantic version of the software the Dockerfile builds, for example Dockerfile.webserver.v1.2.0.

Branches

When different development branches need distinct Dockerfiles, include the branch identifier:

 
Dockerfile.<service-name>.<branch>

This keeps Dockerfiles for different stages of development or testing clearly separated.

Build variants

For configuration differences such as development versus production, add a variant suffix:

 
Dockerfile.<service-name>.<variant>

For example:

  • Dockerfile.api.dev
  • Dockerfile.api.prod

Naming conventions at a glance

Naming StrategySyntaxUse Case
DefaultDockerfileSingle project or simple applications.
Service SpecificDockerfile.<service-name>Multi-service applications to identify each service's Dockerfile.
VersionedDockerfile.<service-name>.<version>To track changes or updates with specific versions.
Branch-SpecificDockerfile.<service-name>.<branch>Different branches requiring distinct Dockerfiles.
Variant-SpecificDockerfile.<service-name>.<variant>Differentiating environments (e.g., dev vs prod) or build configurations.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design