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.
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.
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.
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.