Last active
July 21, 2022 07:09
-
-
Save uzulla/c09c97ba6a75301fd6d78061244d7a7c to your computer and use it in GitHub Desktop.
stop running docker-compose containers in anywhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
docker ps --filter 'label=com.docker.compose.project.config_files' --format '{{ .Labels }}' | sed 's/,/\n/g' | grep com.docker.compose.project.config_files | uniq | cut -d = -f 2 | xargs -I {} -L 1 docker-compose -f {} stop | |
# use jq | |
# docker ps --format '{{json .Labels}}' | xargs echo | sed "s/,/\n/g" |grep com.docker.compose.project.config_files | cut -d = -f 2|uniq | xargs -I {} -L 1 docker-compose -f {} stop | |
Author
uzulla
commented
Jul 21, 2022
<?php
$ndjson = `docker ps --format '{{json .}}'`;
$json_list = explode("\n", $ndjson);
$data_list = array_map(
fn($json) => json_decode($json, true),
$json_list
);
$data_list_filtered = array_filter(
$data_list,
fn($row) => is_array($row)
);
$data_label_prop_list = array_map(
fn($csv) => $csv['Labels'],
$data_list_filtered
);
$container_data_list = array_map(
fn($csv) => explode(",", $csv),
$data_label_prop_list
);
$yaml_path_list = [];
foreach ($container_data_list as $container_array) {
$docker_compose_config_row_list = array_filter(
$container_array,
fn($row) => preg_match("|com.docker.compose.project.config_files|u", $row),
);
$line = array_shift($docker_compose_config_row_list);
[$_, $yaml_path] = explode("=", $line, 2);
$yaml_path_list[] = $yaml_path;
}
$yaml_path_list = array_unique($yaml_path_list);
var_dump($yaml_path_list);
/*
array(1) {
[0]=>
string(52) "/path/to/docker-compose.yml"
}
*/
PoC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment