参考:https://docs.docker.com/engine/reference/commandline/inspect/
数据源:
数据源: [root@host-10-0-101-156 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 056ee68c3788 rayosx:2.0.1 "/bin/bash" 29 hours ago Up 28 hours 0.0.0.0:5901->5900/tcp stupefied_murdock f21025fccdd9 rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5906->5900/tcp romantic_bell ff2dacef1188 rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5907->5900/tcp vibrant_hawking f0831061479f rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5908->5900/tcp
用法:
1、查找端口
[root@host-10-0-101-156 ~]# docker inspect -f='{{range $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}} {{end}}' 056ee68c3788 5901
2、查找端口映射
[root@host-10-0-101-156 ~]# docker inspect -f='{{range $p, $conf := .NetworkSettings.Ports}}{{$p}} -> {{(index $conf 0).HostPort}} {{end}}' 056ee68c3788 5900/tcp -> 5901