From aa020f4462aea42bfeac3022b2d7e95083ec7c6d Mon Sep 17 00:00:00 2001 From: Chai Feng Date: Wed, 3 Oct 2018 09:45:29 +0800 Subject: [PATCH] avoid to find a stopped instance --- ufw-docker | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ufw-docker b/ufw-docker index 2d3bee2..e9ecae7 100755 --- a/ufw-docker +++ b/ufw-docker @@ -44,7 +44,9 @@ function ufw-docker--allow() { docker inspect "$INSTANCE_NAME" &>/dev/null || die "Docker instance \"$INSTANCE_NAME\" doesn't exist." - mapfile -t INSTANCE_IP_ADDRESSES < <(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{"\n"}}{{end}}' "$INSTANCE_NAME" | remove_blank_lines) + mapfile -t INSTANCE_IP_ADDRESSES < <(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{"\n"}}{{end}}' "$INSTANCE_NAME" 2>/dev/null | remove_blank_lines) + + [[ -z "${INSTANCE_IP_ADDRESSES:-}" ]] && die "Could not find a running instance \"$INSTANCE_NAME\"." mapfile -t PORT_PROTO_LIST < <(docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{with $conf}}{{$p}}{{"\n"}}{{end}}{{end}}' "$INSTANCE_NAME" | remove_blank_lines)