Skip to content

How to Start and Stop Docker Compose Services

DodaTech 2 min read

In this tutorial, you'll learn about How to Start and Stop Docker Compose Services. We cover key concepts, practical examples, and best practices.

The Problem

You have a docker-compose.yml file but running <a href="/devops/docker-compose/">docker compose</a> up leaves containers running in the foreground, or <a href="/devops/docker-compose/">docker compose</a> down removes everything including volumes. You need predictable commands to start, stop, and clean up your services.

Quick Fix

Step 1: Start services in detached mode

Run all services in the background:

docker compose up -d
[+] Running 3/3
 ✔ Container app-db-1      Started
 ✔ Container app-api-1     Started
 ✔ Container app-web-1     Started

Step 2: View running services

Check the status of all services:

docker compose ps
NAME                SERVICE             STATUS              PORTS
app-api-1           api                 Up                  0.0.0.0:8080->3000/tcp
app-db-1            db                  Up                  5432/tcp
app-web-1           web                 Up                  0.0.0.0:80->80/tcp

Step 3: Stop services without removing them

Stop containers but keep them for later restart:

docker compose stop
[+] Stopping 3/3
 ✔ Container app-api-1     Stopped
 ✔ Container app-db-1      Stopped
 ✔ Container app-web-1     Stopped

Step 4: Restart stopped services

Restart without recreating containers:

docker compose start

Step 5: Stop and remove everything

Remove containers, networks, and optionally volumes:

docker compose down

To remove volumes too:

docker compose down -v

Step 6: Rebuild and start with fresh images

Rebuild images and start services:

docker compose up -d --build

Alternative Solutions

Restart only a single service

Recreate just one service without affecting others:

docker compose up -d --no-deps --build api

Pause services without stopping

Freeze container processes without removal:

docker compose pause
docker compose unpause

Common Mistakes to Avoid

Using down -v unintentionally. The -v flag removes named volumes, destroying database data. Only use it when you want a full reset.

Not using --build when Dockerfile changes. <a href="/devops/docker-compose/">docker compose</a> up reuses cached images unless you add --build or run <a href="/devops/docker-compose/">docker compose</a> build.

Running up in the wrong directory. <a href="/devops/docker-compose/">docker compose</a> up must be run from the directory containing docker-compose.yml or use -f to specify the file path.

Pro Tips

Use docker compose logs -f --tail=50. Follow logs for all services at once to monitor startup and catch errors: <a href="/devops/docker-compose/">docker compose</a> logs -f --tail=50.

Use docker compose config to validate the file. Check your compose file for errors without running anything: <a href="/devops/docker-compose/">docker compose</a> config parses and validates.

Use docker compose run for one-off commands. Run a command in a new container based on a service definition: <a href="/devops/docker-compose/">docker compose</a> run app npm test.

Use docker compose restart for quick service restarts. When you only need to restart services without rebuilding or re-creating containers, <a href="/devops/docker-compose/">docker compose</a> restart is faster than down followed by up.

Prevention

  • Use <a href="/devops/docker-compose/">docker compose</a> up -d instead of foreground mode for production-style runs.
  • Use <a href="/devops/docker-compose/">docker compose</a> down -v only when you want to reset all data.
  • Use <a href="/devops/docker-compose/">docker compose</a> stop to pause services temporarily without cleanup.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro