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:
One Dockerfile per service: Dockerfile.<service-name>
For projects with multiple services or containers, use:
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:
A multi-service application with a web server, a backend API and a database could look like this:
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:
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:
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:
For example:
Dockerfile.api.devDockerfile.api.prod
Naming conventions at a glance
| Naming Strategy | Syntax | Use Case |
| Default | Dockerfile | Single project or simple applications. |
| Service Specific | Dockerfile.<service-name> | Multi-service applications to identify each service's Dockerfile. |
| Versioned | Dockerfile.<service-name>.<version> | To track changes or updates with specific versions. |
| Branch-Specific | Dockerfile.<service-name>.<branch> | Different branches requiring distinct Dockerfiles. |
| Variant-Specific | Dockerfile.<service-name>.<variant> | Differentiating environments (e.g., dev vs prod) or build configurations. |
Related reading
- How to open rabbitmq in browser using docker container?
- How to override Dockerfile's entrypoint /bin/sh from kubernetes job's deployment yml?
- How to override the CMD command in the docker run line
- How to pass arguments to a Dockerfile?
- How to obtain Certificate Signing Request
- How to organize Terraform modules for multiple environments?
- How to pass arguments to Shell Script through docker run
- How to pass Docker CLI --gpus Options in Kubernetes or enable GPU support without installing nvidia-docker2 Docker 19.03
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.