Docker inspect format retrieve port mapping

I’d like to retrieve the port mapped to a container using docker inspect, I found something like that:

docker inspect --format=" {{ .NetworkSettings.Ports }} " containerid


  • Get docker swarm manager node from jenkins job
  • how can i restore the plugin data of errbot running in a docker container
  • Where are docker images gcloud should build from
  • High Availability for Bluemix Secure Gateway Docker Client
  • Docker compose build error
  • Docker not port forwarding correctly?
  • map[1234/tcp:[map[HostIp: HostPort:49159]] 3306/tcp:<nil> 4444/tcp:<nil> 4567/tcp:<nil> 4568/tcp:<nil>]

    But I’d like to have an output like this:


    Is it possible ?

  • File as command line argument of Docker python app
  • invalid argument creating a ruby dev env with docker & fig
  • Docker - MySQL commands within Dockerfile using RUN (ERROR 2002)
  • Docker Overlay network -service name issue between two nodes
  • Docker: Scaling Python container, memory overhead
  • Forwarding traffic between two interfaces
  • 3 Solutions collect form web for “Docker inspect format retrieve port mapping”

    See also my answer How to get ENV variable when doing Docker Inspect I guess you can adapt and get directly what you want

    The docker port command may be more useful; it produces output like this:

    $ docker port 0a7b4df54966
    443/tcp ->
    80/tcp ->

    You can use index in your template:

    --format '1234/tcp:{{ (index (index .NetworkSettings.Ports "1234/tcp") 0).HostPort }}'
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.