Working with multiple microservices? Docker Compose is your best friend. It lets you start, stop, and manage multiple containers using just a few commands.
In this post, you'll learn the difference between:
docker compose up
docker compose down
docker compose stop
docker compose start
πΌ docker compose up
This command creates and starts your containers based on the docker-compose.yml
file.
docker compose up -d
-
-d
= βdetached modeβ β run containers in the background - It builds containers if they donβt already exist
- Useful for starting fresh or restarting your entire system
π½ docker compose down
This command stops and removes all containers, networks, and volumes created by Docker Compose.
docker compose down
- Cleans up everything
- Helps save space on your machine
- Use it when you're done or want to restart everything fresh
π docker compose stop
This command only stops your running containers. It does not delete them.
docker compose stop
Use this when:
- You want to pause development
- You plan to restart the containers later without rebuilding
βΆοΈ docker compose start
This command restarts containers that were previously stopped using stop
.
docker compose start
β οΈ If the containers were removed using down
, this command won't work β they no longer exist.
π‘ Real Example Flow
Hereβs a typical workflow when using Docker Compose:
# Start all services
docker compose up -d
# Stop them without removing
docker compose stop
# Start them again
docker compose start
# Stop and remove everything
docker compose down
β Summary Table
Command | Action | Removes Containers? |
---|---|---|
docker compose up |
Builds & runs containers | β No |
docker compose stop |
Stops containers only | β No |
docker compose start |
Starts containers that were stopped | β No |
docker compose down |
Stops and removes everything | β Yes |
π Final Notes
- Most of the time, you'll use
up
anddown
. - If you're working on a project temporarily,
stop
andstart
are great tools to keep things light. - Always double-check your
docker-compose.yml
file β correct indentation is very important!
Let me know if you'd like me to add:
- A visual diagram to help reinforce this flow
- A downloadable cheat sheet
- A GitHub sample project
Happy Dockering! π³
Top comments (0)