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

