暴露的 docker 端口无法从外部访问

Exposed docker ports not accessible from outside

我正在尝试 运行 apache2 inside docker 但是当我公开端口时,该服务只能从主机访问,不能从外部访问。

我通过以下方式执行了容器:

docker run -d -t -p 8080:80 --name ctf ubuntu

之后我在里面安装了apache2:

apt-get update && apt-get install apache2 -y && service apache2 start

当我 运行 docker ps 我会得到:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES 
c90b8ed41436        ubuntu              "/bin/bash"         3 minutes ago       Up 3 minutes        0.0.0.0:8080->80/tcp   ctf

我可以通过 wget <public ip>:8080 从该主机访问该服务。但是,如果我尝试从同一网络上的另一台设备进行尝试,它就无法正常工作。无法访问该服务。

另外命令 iptables --list 将产生:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             anywhere             udp dpt:openvpn

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  10.8.0.0/24          anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:http

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

您知道问题出在哪里吗?

编辑:

编辑2: 来自 netstat -ntlp 的结果,似乎 docker 没有将套接字绑定到 IPv4:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     
tcp        0      0 0.0.0.0:10022           0.0.0.0:*               LISTEN      423/./ts3server
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      13863/mysqld
tcp        0      0 127.0.0.1:37995         0.0.0.0:*               LISTEN      15022/containerd
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1577/apache2
tcp        0      0 0.0.0.0:30033           0.0.0.0:*               LISTEN      423/./ts3server
tcp        0      0 0.0.0.0:8084            0.0.0.0:*               LISTEN      1552/mono
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      19145/systemd-resol
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1561/sshd
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1577/apache2
tcp        0      0 0.0.0.0:10011           0.0.0.0:*               LISTEN      423/./ts3server      
tcp6       0      0 :::10022                :::*                    LISTEN      423/./ts3server
tcp6       0      0 :::8080                 :::*                    LISTEN      16111/docker-proxy
tcp6       0      0 :::30033                :::*                    LISTEN      423/./ts3server
tcp6       0      0 :::22                   :::*                    LISTEN      1561/sshd
tcp6       0      0 :::10011                :::*                    LISTEN      423/./ts3server

但这应该不是问题,因为:

root@ubuntu:~/docker# sysctl net.ipv6.bindv6only 
net.ipv6.bindv6only = 0
root@ubuntu:~/docker# sysctl net.ipv6.conf.all.forwarding 
net.ipv6.conf.all.forwarding = 1

问题是当前 wifi 端口 8080 被过滤:( 抱歉