liveBook · Manning

Docker compose down

As explained in Road to Kubernetes

docker compose down is a Docker Compose command that stops and removes application services and can optionally remove managed volumes.

docker compose down stops a running Compose application and cleans up its services and networks. Use it instead of interrupting the process when Compose should manage the shutdown. section 6.2.2 section 6.4.2

Choose the form of the command according to the data you need to preserve:

  • Run docker compose down to stop services while preserving data in Docker Compose-managed mounted volumes. section 6.3.2 section 6.4.2
  • Run docker compose down -v, or --volumes, to remove Compose-managed volumes and destroy their files and data. section 6.3.3 section 6.3.2
  • Expect host-managed or external volumes to remain; Compose does not remove them with the -v option. section 6.3.3 section 6.3.2
  • Add --remove-orphans after changing or removing service names to take down leftover services and networks. section 6.4.2

Stop a Python application safely

Start the application with docker compose up, open another terminal in the project directory, and run docker compose down. The web container stops while its Compose-managed mounted data remains. Use docker compose down -v only when destroying that managed data is intended. section 6.2.2 section 6.3.3 section 6.4.2

Listing 6.7 Managing volumes with Docker Compose
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - PORT=8080
    volumes:
      - mywebdata:/app/data

volumes:
  mywebdata:

Shows a Compose-managed mywebdata volume mounted at /app/data, making the scope of the -v option concrete. section 6.3.3

How Road to Kubernetes covers it

How deep it goes
Explains normal shutdown, volume deletion, external-volume protection, and orphan removal without descending into Compose internals.
Examples
Uses a Python web container, Compose-managed application data, Redis, and database-volume persistence to demonstrate shutdown choices.
What it assumes
Assumes a Compose project and running services, while teaching the difference between managed, host-managed, and external volumes.
What you can do after
Operate/configure Compose environments by stopping services, preserving data, or deliberately removing managed volumes.
How it connects
Connects Docker Compose services, networks, mounted volumes, external volumes, and containerized databases.

Also explained in

Compare how 2 books explain docker compose down →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.