Docker vs Docker Compose
A common question for beginners is: "What is the difference between Docker and Docker Compose?"
The Short Answer
- Docker (specifically the
dockerCLI) is used to manage individual containers. - Docker Compose is used to manage multi-container applications.
Comparison Table
| Feature | Docker CLI (docker run) | Docker Compose (docker compose up) |
|---|---|---|
| Scope | Single Container | Multi-Container Application |
| Configuration | Command line flags | YAML file (docker-compose.yml) |
| Networking | Manual (--network) | Automatic (creates a default network) |
| Volumes | Manual (-v) | Defined in YAML, easy to reuse |
| Reproducibility | Low (long commands) | High (config as code) |
| Use Case | Quick tests, one-off scripts | Development environments, production stacks |
When to use Docker CLI
Use docker run when you just need to spin up a single tool quickly.
Example: Running a quick Python script.
docker run -it --rm python:3.9 python -c "print('Hello World')"
When to use Docker Compose
Use Docker Compose for anything that involves more than one container, or even a single container if you want to save the configuration.
Example: Running a web server that needs a database.
docker-compose.yml:
services:
web:
image: my-web-app
ports: ["80:80"]
db:
image: postgres
environment:
POSTGRES_PASSWORD: secret
Command:
docker compose up -d
Dockerfile vs Docker Compose
Another common confusion is between Dockerfile and docker-compose.yml.
- Dockerfile: A recipe for building a Docker image. It tells Docker how to create the image (install apt packages, copy code, set env vars).
- docker-compose.yml: A recipe for running containers. It tells Docker how to run images (which ports to open, which volumes to mount, which networks to join).
You often use them together: Compose reads your Dockerfile to build the image, then runs it.
Hostim supports both
Whether you have a single Docker image or a complex Compose stack, Hostim.dev runs it on bare metal with zero config.