DOCKER – Get published port for a service

If you want/need to get the given Published Port for a given target port in a docker service you can use:

docker service inspect SERVICE_NAME --format='{{range .Endpoint.Ports}}{{if eq .TargetPort 8080}}{{.PublishedPort}}{{end}}{{end}}'

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.