在Docker容器的日常使用中,有以下5種常見的端口映射方式
- 對容器暴露的所有端口,隨機映射宿主機端口
-P , –publish-all=true | false,默認為false
docker run -P -it ubuntu /bin/bash
- 映射宿主機隨機端口到容器指定端口
-p containerPort( -p表示 –publish=[ ] )
docker run -p 80 -it ubuntu /bin/bash
- 映射宿主機指定端口到容器指定端口(一 一對應)
hostPort : containerPort
docker run -p 8080:80 -it ubuntu /bin/bash
- 指定容器IP和容器端口,宿主機端口隨機映射
ip : : containerPort
docker run -p 127.0.0.12::80 -it ubuntu /bin/bash
- 指定容器IP、宿主機端口、容器端口
ip : hostPort : containerPort
docker run -p 127.0.0.12:8080:80 -it ubuntu /bin/bash
IP規則
查看ip規則
iptables -t nat -L -n
添加子網ip
ifconfig eth0:1 10.0.0.100/24 up