我想将数据库访问权限限制为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
。
传入的流量将作为下一个:
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
,因此没有外国主机可以访问您的主机,因此也无法访问您的容器。