Files
mtusi2026lab3-fork/scripts/stop-one.sh
T
2026-10-23 18:10:07 +03:00

20 lines
559 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
# Находим ID контейнера, чьё имя (HOSTNAME) совпадает с TARGET_INSTANCE_ID.
CID=$(docker compose ps -q api | while read -r id; do
name=$(docker inspect --format '{{.Config.Hostname}}' "$id")
if [ "$name" = "$TARGET_INSTANCE_ID" ]; then
echo "$id"
break
fi
done)
if [ -z "$CID" ]; then
echo "container with hostname $TARGET_INSTANCE_ID not found" >&2
exit 2
fi
docker stop "$CID"
echo "stopped $CID ($TARGET_INSTANCE_ID)"