无法从外部访问公开的docker端口

时间:2019-10-25 14:40:38

标签: docker ubuntu port

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

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

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

您知道问题出在哪里吗?

编辑: Connectivity test

EDIT2: 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

1 个答案:

答案 0 :(得分:0)

问题是,在当前的wifi上,端口8080已被过滤:(对不起