我在使用以下命令运行的 docker 实例中运行了一个 web 服务:
sudo docker run -d -p 4040:4040 ....
Run Code Online (Sandbox Code Playgroud)
我的 UFW 规则如下所示:
~ sudo ufw status
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
4040 DENY Anywhere
22 ALLOW Anywhere (v6)
4040 DENY Anywhere (v6)
Run Code Online (Sandbox Code Playgroud)
当我通过它的IP直接访问盒子时,我可以访问端口4040。为什么ufw规则没有阻止它?
注意:作为docker安装的一部分,我改变了
DEFAULT_FORWARD_POLICY="DROP" 到 DEFAULT_FORWARD_POLICY="ACCEPT"
在 /etc/default/ufw 根据此处的 dockers 说明(http://docs.docker.io/en/latest/installation/ubuntulinux/#docker-and-ufw)