Dockerfile vs Docker Compose

docker

Updated August 29, 2026

A Dockerfile and a Compose file answer different questions.

A Dockerfile describes how to build one image: its base, files, dependencies, and default process. Compose describes how to run one or more services together: images/build contexts, ports, networks, volumes, environment, and dependencies.

A common project has both:

services:
  web:
    build: .
    ports:
      - "8080:3000"

The build: . line tells Compose to use the Dockerfile in the context directory. Compose does not replace the Dockerfile's build instructions, and a Dockerfile does not create a database, network, or multi-service development environment by itself.

Use docker build when you need a reusable image and docker compose up when you need the defined local stack. Keep secrets out of committed Compose files, pin dependencies intentionally, and remember that Compose manages services on a host; production orchestration may require a different platform.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author