如何查看容器端口到宿主机端口的映射关系?
使用docker port命令进行查看
# 查看容器的ID
[root@nccztsjb-node-27 ~]# docker ps | grep nginx 78e7140c0b8c goharbor/nginx-photon:v2.6.1 "nginx -g 'daemon of…" 2 months ago Up 2 months (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx 3327bc10a1ba goharbor/harbor-portal:v2.6.1 "nginx -g 'daemon of…" 2 months ago Up 2 months (healthy) harbor-portal [root@nccztsjb-node-27 ~]#
# 78e7140c0b8c是容器的ID
[root@nccztsjb-node-27 ~]# docker port 78e7140c0b8c 8080/tcp -> 0.0.0.0:80 8080/tcp -> :::80
# 也可以用容器的名字
[root@nccztsjb-node-27 ~]# docker port nginx 8080/tcp -> 0.0.0.0:80 8080/tcp -> :::80 [root@nccztsjb-node-27 ~]#
docker port的输出中,左边额一列,箭头的左边是容器内的端口号,箭头的右边是在宿主机上映射出来的端口好,绑定到哪个IP,哪个具体的端口上了。