diff --git a/bin/compose b/bin/compose index 8f01e94..765b754 100755 --- a/bin/compose +++ b/bin/compose @@ -309,30 +309,13 @@ list_compose_vars() { } -get_running_compose_containers() { - ## XXXvlab: docker bug: there will be a final newline anyway - docker ps --filter label="compose.service" --format='{{.ID}}' -} - - -get_volumes_for_container() { - local container="$1" - - docker inspect \ - --format '{{range $mount := .Mounts}}{{$mount.Source}}{{"\x00"}}{{$mount.Destination}}{{"\x00"}}{{end}}' \ - "$container" -} - - is_volume_used() { - local volume="$1" - - while read container_id; do - while read-0 src dst; do - [ "$src" == "$volume" ] && return 0 - done < <(get_volumes_for_container "$container_id") - done < <(get_running_compose_containers) - return 1 + local volume="$1" out + if ! out=$(docker ps --filter volume="$volume" --format {{.ID}}); then + err "Couldn't query containers by volumes." + return 0 + fi + [ -n "$out" ] } diff --git a/bin/compose-core b/bin/compose-core index 4ad4ba2..112f867 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -3325,14 +3325,12 @@ get_volumes_for_container() { export -f get_volumes_for_container is_volume_used() { - local volume="$1" container_id src dst - - while read -r container_id; do - while read-0 src dst; do - [[ "$src/" == "$volume"/* ]] && return 0 - done < <(get_volumes_for_container "$container_id") - done < <(get_running_compose_containers) - return 1 + local volume="$1" out + if ! out=$(docker ps --filter volume="$volume" --format {{.ID}}); then + err "Couldn't query containers by volumes." + return 0 + fi + [ -n "$out" ] } export -f is_volume_used