Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mrgnw/scripts.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677#!/usr/bin/env bash# Remove *exited* containers from the inactive local Huly and Teable stacks.## This intentionally never removes volumes, images, networks, or running# containers. It is a dry run unless --apply is supplied.
set -euo pipefail
readonly docker_bin="${DOCKER_BIN:-docker}"readonly -a projects=(huly_v7 teable)
apply=false
usage() { cat <<'EOF'Usage: docker-clean-huly-teable [--apply]
List exited Docker Compose containers belonging to the Huly (huly_v7) andTeable (teable) projects. This is a dry run by default.
--apply remove the listed containers -h, --help show this help
Only containers whose current Docker status is "exited" and whose Composeproject label exactly matches huly_v7 or teable are selected. --apply uses"docker container rm" without --force or --volumes, so Docker will not removerunning containers, volumes, images, or networks.EOF}
while [[ $# -gt 0 ]]; do case "$1" in --apply) apply=true ;; -h|--help) usage; exit 0 ;; *) echo "error: unknown argument: $1" >&2 usage >&2 exit 2 ;; esac shiftdone
if ! command -v "$docker_bin" >/dev/null 2>&1; then echo "error: Docker command not found: $docker_bin" >&2 exit 127fi
container_ids=()for project in "${projects[@]}"; do while IFS= read -r container_id; do [[ -n "$container_id" ]] && container_ids+=("$container_id") done < <("$docker_bin" ps -aq \ --filter status=exited \ --filter "label=com.docker.compose.project=$project")done
if [[ ${#container_ids[@]} -eq 0 ]]; then echo "No exited Huly or Teable containers found." exit 0fi
echo "Exited containers selected by exact Compose project label:"for project in "${projects[@]}"; do "$docker_bin" ps -a --filter status=exited \ --filter "label=com.docker.compose.project=$project" \ --format '{{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}'done
if ! "$apply"; then echo "Dry run — re-run with --apply to remove these containers." exit 0fi
echo "Removing ${#container_ids[@]} exited container(s); volumes, images, and networks are preserved.""$docker_bin" container rm "${container_ids[@]}"