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

Output:

  • Docker pull repositoryName don't work can't see public repos
  • Cannot locate specified Dockerfile
  • Container doesn't exist after Rest API successfully creates it
  • How can I transfer my docker image to another computer?
  • What does CREATED container mean in docker?
  • Make JMX work with spotify/kafka Docker image
  • map[1234/tcp:[map[HostIp:0.0.0.0 HostPort:49159]] 3306/tcp:<nil> 4444/tcp:<nil> 4567/tcp:<nil> 4568/tcp:<nil>]
    

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

    1234/tcp:49159
    

    Is it possible ?

  • Docker container vs Java Virtual Machine
  • Docker Compose when to use image over build
  • How to efficiently copy lots of Docker images from one private registry to another?
  • “docker images” command doesn't show correct size
  • Elasticsearch deployment on google app engine flex
  • Json schema Draft v4 to markdown documentation
  • 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 -> 0.0.0.0:4430
    80/tcp -> 0.0.0.0:8888
    

    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.