check published port of a service

This commit is contained in:
Chai Feng 2018-10-03 09:11:55 +08:00
parent a91e864cfe
commit 2c5391dcec
No known key found for this signature in database
GPG Key ID: 2DCD9A24E523FFD2

View File

@ -130,6 +130,19 @@ function ufw-docker--service-allow() {
return 1
fi
declare port="${service_port%/*}"
declare proto="(tcp|udp)"
[[ "$service_port" = */* ]] && proto="${service_port#*/}"
if ! docker service inspect "$service_name" \
--format '{{range .Endpoint.Spec.Ports}}{{.TargetPort}}/{{.Protocol}}{{end}}' |
grep -E "^${port}/${proto}\$"; then
die "Service $service_name does not publish port $service_port."
return 1
fi
service_label="ufw.public.${service_name}=${service_port}"
}
function ufw-docker--install() {