运行 docker 容器:iptables:没有该名称的链/目标/匹配
Posted
技术标签:
【中文标题】运行 docker 容器:iptables:没有该名称的链/目标/匹配【英文标题】:Running docker container : iptables: No chain/target/match by that name 【发布时间】:2015-10-18 11:15:24 【问题描述】:我正在尝试运行容器,但遇到以下问题:
Error response from daemon: Cannot start container b005715c40ea7d5821b15c44f5b7f902d4b39da7c83468f3e5d7c042e5fe3fbd: iptables failed: iptables --wait -t filter -A DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.43 --dport 80 -j ACCEPT: iptables: No chain/target/match by that name.
(exit status 1)
这是我使用的命令:
docker run -d -p 10080:80 -v /srv/http/website/data:/srv/http/www/data -v /srv/http/website/logs:/srv/http/www/logs myimage
在我的服务器上打开端口 80 还不够吗? docker界面有什么我错过的吗? 我将 iptables 与这样的脚本一起使用:
#!/bin/sh
# reset :
iptables -t filter -F
iptables -t filter -X
# Block all :
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP
# Authorize already established connections :
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Authorize backloop :
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
# Authorize ssh :
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT
# Authorize HTTP :
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
# Authorize HTTPS :
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
# Authorize DNS :
iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
# Ping :
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT
# Authorize FTP :
iptables -t filter -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 21 -j ACCEPT
# # Authorize NTP :
# iptables -t filter -A INPUT -p udp --dport 123 -j ACCEPT
# iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
# Authorize IRC :
iptables -t filter -A INPUT -p tcp --dport 6667 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 6667 -j ACCEPT
# Authorize port 10000 (for Node.JS server) :
iptables -t filter -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 10000 -j ACCEPT
# Authorize port 631 (Cups server) :
iptables -t filter -A INPUT -p tcp --dport 631 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 631 -j ACCEPT
# Authorize port 9418 (git) :
iptables -t filter -A INPUT -p tcp --dport 9418 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 9418 -j ACCEPT
我该如何解决这个问题?
【问题讨论】:
我在answer之前回答过这个问题 【参考方案1】:我认为问题出在以下几行之内:
iptables -t 过滤器 -F
iptables -t 过滤器 -X
这确实清除了所有链条。一种可能的解决方案是在 iptables 设置脚本之后启动 docker 守护进程。否则,您将需要明确删除您感兴趣的链。
【讨论】:
谢谢!这就是问题所在:我刚刚重新启动了 docker 守护进程,现在一切正常! 运行此命令时要小心。如果你在远程服务器上运行它,它也会导致你的 ssh 会话终止。【参考方案2】:安装firewalld后我遇到同样的问题。
我通过以下方式修复它:
service firewalld stop
service docker restart
【讨论】:
这对我有用,但不知道停止firewalld是否有任何重大安全风险。 这对我也有用,但是在重新启动 docker 后,我重新打开了防火墙,然后启动了容器。错误消息随即消失。【参考方案3】:我可以确认这个问题是由 iptables 或 firewalld 引起的,因为在我的容器停止之前,我编辑了防火墙的规则。
iptables -t filter -X
iptables -t filter -F
【讨论】:
【参考方案4】:是的,我遇到了同样的问题,如上所述,下面的命令对我有用
sudo iptables -t filter -F
sudo iptables -t filter -X
systemctl restart docker
【讨论】:
【参考方案5】:该错误可能发生,因为它试图影响 iptables “DOCKER”过滤器链,但不存在。
选项 --iptables=false 可防止 docker 更改 iptables 配置。
(来源:https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/#communicating-to-the-outside-world)
如果您选择修复 iptables docker 过滤器链,请按以下步骤操作。
您实际上可以编辑 iptables 并添加它,使其看起来像这里的示例 Docker: How to re-create dockers additional iptables rules?
像这样
sudo vi /etc/sysconfig/iptables
添加 ":DOCKER" 行
*nat
:PREROUTING ACCEPT [144:8072]
:INPUT ACCEPT [87:5208]
:OUTPUT ACCEPT [118:8055]
:POSTROUTING ACCEPT [118:8055]
:DOCKER - [0:0]
... your previous rules here ...
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5781:5099614]
:DOCKER - [0:0]
... your previous rules here ...
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
COMMIT
重新启动...例如
service iptables restart
一个很好的“进一步阅读”链接,解释得很好
https://medium.com/@ebuschini/iptables-and-docker-95e2496f0b45
【讨论】:
【参考方案6】:在 RHEL 7 上遇到了同样的问题。重新启动 docker 服务对我有用,无需刷新任何 iptable
规则。
$ sudo systemctl restart docker
【讨论】:
我强烈建议遇到此问题的任何人查看此解决方案。它为我节省了很多时间。 是的,这只是一种解决方法。不知道需要做什么来避免它。【参考方案7】:我在 docker-compose 设置中遇到了同样的问题。
1.清除所有连锁店:
sudo iptables -t filter -F
sudo iptables -t filter -X
2。然后重启 Docker 服务:
systemctl restart docker
【讨论】:
对我来说systemctl restart docker
没有冲洗 iptables
工作得很好!
重启 docker 守护进程也对我有用,谢谢!我记得前几天我必须清除所有 iptables 表,它还清除了 docker 安装的表。【参考方案8】:
在 irc.freenode.net#docker 中,您声明您在 Raspberry Pi 上使用 Arch Linux ARM。
如果您没有将此脚本作为 systemd 服务的一部分运行,我强烈建议您移至该脚本,或利用现有的 iptables 服务并利用它们在适当时间保存/恢复表的能力。如果您选择转移到自己的服务,请确保单位声明已订购Before=docker.service
【讨论】:
以上是关于运行 docker 容器:iptables:没有该名称的链/目标/匹配的主要内容,如果未能解决你的问题,请参考以下文章