# Dockerfile

> A text file of steps. It builds a container image, one line at a time.

**Field:** Infrastructure  
**Category:** Containers  
**Also known as:** Containerfile, Docker File

## Think of it like

It is like a recipe card. Follow the steps in order, and you bake the same cake each time.

## Definition

A Dockerfile is a plain text file of steps for building a container image. Each line is one step. FROM picks the image to start from. COPY adds your files, and RUN runs a command while the image is built. CMD says what to run when a container starts. The docker build command reads the file and makes the image.

## Example

Emma's file starts from an official Python image. It copies her app in and adds its packages. Anyone on her team can build the same image with one command.

## Example code

```dockerfile
FROM python:3.13-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
```

Start from Python, copy the app in, install its packages, then say how to run it.

## Why it matters

The build lives in a file, not in someone's head. Anyone can rebuild the image, and every change is saved with the code.

## Common mistake

Copying secret keys into the image. Anyone who gets the image can read each file in it.

## Three principles

- **One step a line.** Each line adds a layer or a setting.
- **Order matters.** Put steps that rarely change first.
- **Kept with the code.** It sits in the project, under version control.

## Related terms

- [Container Image](https://learn.benibix.com/term/infrastructure/container-image)
- [Docker](https://learn.benibix.com/term/infrastructure/docker)
- [Container Registry](https://learn.benibix.com/term/infrastructure/container-registry)
- [Build (Software)](https://learn.benibix.com/term/development/build)
- [Version Control](https://learn.benibix.com/term/development/version-control)
- [Base Image](https://learn.benibix.com/term/infrastructure/base-image)
- [Multi-Stage Build](https://learn.benibix.com/term/infrastructure/multi-stage-build)

## Told apart from

- [Dockerfile vs Docker Compose](https://learn.benibix.com/compare/dockerfile-vs-docker-compose): People think a compose file replaces the Dockerfile, and it does not. A Dockerfile says how to build one image. A compose file says which containers to run together and how they link. The compose file often points to a Dockerfile to build from. Most apps with two or more containers use both.

![A row of steps from left to right. A Dockerfile is built into an image. The image is pushed up to a registry. A server pulls the image down from the registry and runs it as two containers.](https://learn.benibix.com/diagrams/inf-image-flow.svg)

---

Source: https://learn.benibix.com/term/infrastructure/dockerfile
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
