Docker # Docker 报错
-p 指定端口
8000:8080
宿主机:docker内端口
端口映射启动报错
解决方法:重启docker
[root@real-kk ~]# docker run -d -p 8080:80 centos:7
379f3329ceb4489e2d50a01c9836e6e474a70b66e9b0bb44490c6f23f936065e
docker: Error response from daemon: driver failed programming external connectivity on endpoint elegant_napier (8f8d03528e2b65418b50c3fc21f6ac47253e443e6788326f6ac730c6448de4dd): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 172.17.0.3:80 ! -i docker0: iptables: No chain/target/match by that name.
[root@real-kk ~]# docker run -i -t -p 127.0.0.1:8090:8080 centos:7 /bin/bash
docker: Error response from daemon: driver failed programming external connectivity on endpoint magical_johnson (e4ed6937ea507cef0d89a62a06dc2ed788a5ff62ae2276f5813d18b0ee0ac7d2): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 127.0.0.1 --dport 8090 -j DNAT --to-destination 172.17.0.3:8080 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
ERRO[0000] error waiting for container: context canceled
#################################################################
[root@real-kk ~]# systemctl restart docker
[root@real-kk ~]# docker start tomcat
tomcat
[root@real-kk ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac8702f8d5db tomcat:1 "bash" 53 seconds ago Up 4 seconds 0.0.0.0:8000->80/tcp tomcat
映射多个端口:
[root@real-kk ~]# docker run -p 8080:8080 -p 8081:8081 -p 8082:8082 -p 8083:8083 -it --name tomcat --hostname Tomcat --privileged=true tomcat:1 bash
查看docker映射的所有端口
[root@real-kk ~]# iptables -nL
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 172.17.0.2 tcp dpt:8083
ACCEPT tcp -- 0.0.0.0/0 172.17.0.2 tcp dpt:8082
ACCEPT tcp -- 0.0.0.0/0 172.17.0.2 tcp dpt:8081
ACCEPT tcp -- 0.0.0.0/0 172.17.0.2 tcp dpt:8080
浏览器访问ip:端口