DEV Community

SOVANNARO
SOVANNARO

Posted on

🐳 Docker Compose Basics: `up`, `down`, `stop`, and `start` Explained Simply

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
Enter fullscreen mode Exit fullscreen mode
  • -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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

⚠️ 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
Enter fullscreen mode Exit fullscreen mode

βœ… 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 and down.
  • If you're working on a project temporarily, stop and start 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)