Docker仅将端口公开给本地主机

问题描述 投票:0回答:1

我想将数据库访问权限限制为127.0.0.1,所以我执行了以下命令:

docker run -it mysql:5.5 -p 127.0.0.1:3306:3306 -name db.mysql 

但是我有些困惑...

您可以在这里看到只转发127.0.0.1的端口:

; docker ps
mysql:5.5     127.0.0.1:3306->3306/tcp   db.mysql

有趣的是,我在iptables中找不到此限制:

; iptables -L
Chain FORWARD (policy DROP)
DOCKER     all  --  anywhere             anywhere

Chain DOCKER (2 references)                                                                                                                                                                  
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             192.168.112.2        tcp dpt:mysql

此规则的来源是anywhere

docker iptables
1个回答
0
投票

传入的流量将作为下一个:

Incoming package to host's network -> use ip tables to forward to container

而且,您的限制不在iptables中,而是在主机的网络中,您只打开了3306上的127.0.0.1绑定,而不是0.0.0.0,因此,您当然在iptables中看不到任何内容。 127.0.0.1:3306:3306表示hostIp:hostPort:containerPort

您可以通过netstat -oanltp | grep 3306进行确认,以查看是否没有0.0.0.0,因此没有外国主机可以访问您的主机,因此也无法访问您的容器。

© www.soinside.com 2019 - 2024. All rights reserved.