docker -p 时iptables无效问题

有点标题党嫌疑,本质上是chain链顺序问题html

问题复现linux

$ docker run -d -p 11111:80 nginx:alpine
$ iptables -A INPUT -p tcp --dport 11111 -j DROP
$ curl -I http://localhost:11111

HTTP/1.1 200 OK
Server: nginx/1.15.1
Date: Fri, 07 Sep 2018 09:12:59 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 06 Jul 2018 16:50:07 GMT
Connection: keep-alive
ETag: "5b3f9dbf-264"
Accept-Ranges: bytes

复制代码

若是各位大佬跟我同样,对linux基础知识不牢固,对iptables仅仅停留在baidu阶段,会很纠结nginx

$ iptables -L INPUT -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:11111
复制代码

命名已经添加了DROP,也已经生效了,咋就是很差使呢?docker

经过翻查docker文档Docker and iptables发现,应该使用bash

iptables -I DOCKER-USER -p tcp --dport 11111 -j DROP 
复制代码

具体知识请自行百度curl

相关文章
相关标签/搜索