Docker inspect format retrieve port mapping

后端 未结 3 1326
误落风尘
误落风尘 2021-02-13 01:55

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

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


        
相关标签:
3条回答
  • 2021-02-13 02:04

    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
    
    0 讨论(0)
  • 2021-02-13 02:18

    You can use index in your template:

    --format '1234/tcp:{{ (index (index .NetworkSettings.Ports "1234/tcp") 0).HostPort }}'
    
    0 讨论(0)
  • 2021-02-13 02:27

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

    0 讨论(0)
提交回复
热议问题