Skip to content

Instantly share code, notes, and snippets.

@supermarsx
Last active April 16, 2026 11:13
Show Gist options
  • Select an option

  • Save supermarsx/bac0d2b76758e54c175300b28b7a0cdd to your computer and use it in GitHub Desktop.

Select an option

Save supermarsx/bac0d2b76758e54c175300b28b7a0cdd to your computer and use it in GitHub Desktop.
Shutdown and remove all Docker Compose containers subfolders within a directory

Shutdown every Docker Compose stack in a directory tree

One-liner & script to stop (and remove) all Compose projects that live in sub-folders.

1. Quick copy-paste one-liner

find . -type f \( -name "docker-compose.yml" -o -name "compose.yaml" \) \
  -execdir sh -c 'echo "↓ Stopping in $(pwd)"; docker compose down' \;

Paste it at the root of your workspace.
It will descend into every sub-directory containing docker-compose.yml or compose.yaml and run docker compose down there.

2. Optional reusable script

shutdown-all-docker-compose.sh
#!/usr/bin/env bash
# Shut down EVERY Docker Compose project below the current directory.

set -euo pipefail

find . -type f \( -name "docker-compose.yml" -o -name "compose.yaml" \) \
  -execdir sh -c '
    echo -e "\n\033[1;34m↓ Stopping Compose project in $(pwd)\033[0m"
    docker compose down
  ' {} \;

echo -e "\n✅  All Compose projects stopped."
  1. Save, then give it permission: chmod +x shutdown-all-docker-compose.sh
  2. Run from the directory that contains your projects: ./shutdown-all-docker-compose.sh

3. How it works - step-by-step

Piece Purpose
find . Start searching from the current directory downward.
-type f Only look at files (not dirs).
\( -name "docker-compose.yml" -o -name "compose.yaml" \) Match either Compose file name.
-execdir … \; For each match, cd to the file’s directory and run the given command.
docker compose down Stop & remove that stack’s containers, networks, and default volumes.

4. Safety & tweaks

Need Adjustment
Dry-run first Replace docker compose down with echo docker compose down to just list what would happen.
Remove named volumes too Add --volumes: docker compose down --volumes
Remove images as well Add --rmi all
Old Compose (v1) Change docker composedocker-compose

Tip: If you want an even deeper clean afterwards, run docker system prune manually.

5. Requirements

  • Docker Compose v2 (CLI sub-command form: docker compose …).
  • Bash or POSIX-compatible shell.
  • File system where your projects live under a common parent folder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment