Skip to content
BENIBIX Learn

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.

Infrastructure📦 Containers

Dockerfile

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

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.
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.
Full entry
Infrastructure📦 Containers

Docker Compose

A tool that starts a group of containers. One file and one command do it.

Docker Compose runs an app made of several containers from one file. It names the file compose.yaml. The file lists each container, called a service, with its image, ports and volumes. One command starts them all on a shared network. Another command stops and removes them all.

Example
Emma's app needs a web server, a database and a cache. Her file lists all three. A new teammate starts the whole thing with one command.
Why it matters
The whole setup lives in one file, so anyone can start it the same way.
Full entry

In one line

Dockerfile
A text file of steps. It builds a container image, one line at a time.
Docker Compose
A tool that starts a group of containers. One file and one command do it.