Skip to content
BENIBIX Learn

Dockerfile

Infrastructure📦 ContainersImage Builds

Also known as Containerfile, Docker File

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

Think of it like

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

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.

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.

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 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.
The Dockerfile is the first step. Building it turns the recipe into an image.

Common mistake

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

Key takeaways

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

Compare