Skip to content

Instantly share code, notes, and snippets.

@terashim
Last active July 23, 2023 19:40
Show Gist options
  • Save terashim/19f7e1b314f8a8904bed565c90972b59 to your computer and use it in GitHub Desktop.
Save terashim/19f7e1b314f8a8904bed565c90972b59 to your computer and use it in GitHub Desktop.
List or down all Docker Compose projects running on your machine
#!/usr/bin/env bash
#
# Down all running Docker Compose projects
#
docker ps --filter "label=com.docker.compose.project" -q |\
xargs docker inspect |\
jq -r 'map( .Config.Labels ) |
map({"
project": ."com.docker.compose.project",
"working_dir": ."com.docker.compose.project.working_dir",
"config_files": (."com.docker.compose.project.config_files" | split(","))
}) |
unique |
sort_by(.project) |
.[] |
"cd " + .working_dir + " && docker compose " + ( .config_files | map("-f " + .) | join(" ")) + " down"' |\
xargs -IXXX bash -c XXX;
#!/usr/bin/env bash
#
# List all running Docker Compose projects
#
docker ps --filter "label=com.docker.compose.project" -q |\
xargs docker inspect |\
jq -r 'map( .Config.Labels ) |
map({
"project": ."com.docker.compose.project",
"working_dir": ."com.docker.compose.project.working_dir",
"config_files": (."com.docker.compose.project.config_files" | split(","))
}) |
unique |
sort_by(.project)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment