运行docker container:iptables:没有链/目标/匹配该名称

vmo*_*eco 27 port iptables docker

我正在尝试运行容器,但我遇到以下问题:

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)
Run Code Online (Sandbox Code Playgroud)

这是我使用的命令:

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
Run Code Online (Sandbox Code Playgroud)

是不是在我的服务器上打开端口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
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题?

Man*_*ger 36

我在docker-compose设置中遇到了同样的问题.

1.清除所有链条:

sudo iptables -t filter -F
sudo iptables -t filter -X
Run Code Online (Sandbox Code Playgroud)

2.然后重启Docker Service:

systemctl restart docker
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,在不刷新`iptables`的情况下,`systemctl restart docker`就可以了! (2认同)

Yoa*_*Gil 26

我认为这个问题属于这个问题:

iptables -t filter -F

iptables -t filter -X

这使得所有的链都变得清晰.一种可能的解决方案是在iptables安装脚本之后启动docker守护程序.否则,您需要明确删除您感兴趣的链.

  • 谢谢!这就是问题:我刚刚重启了docker守护进程,现在一切正常! (10认同)
  • 运行此命令时要小心。如果您在远程服务器上运行它,它也会导致您的 ssh 会话终止。 (2认同)

小智 12

我遇到同样的问题,安装firewalld后。

我通过以下方式修复它:

service firewalld stop
service docker restart
Run Code Online (Sandbox Code Playgroud)


Jun*_*aid 10

Faced the same issue on RHEL 7. Restarting docker service worked for me without a need to flush any iptable rules.

$ sudo systemctl restart docker
Run Code Online (Sandbox Code Playgroud)


Jos*_*rez 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:如何重新创建 dockers 附加 iptables 规则?

像这样

sudo vi /etc/sysconfig/iptables
Run Code Online (Sandbox Code Playgroud)

添加“: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
Run Code Online (Sandbox Code Playgroud)

重新启动...例如

service iptables restart
Run Code Online (Sandbox Code Playgroud)

一个很好的“进一步阅读”链接,其中有很好的解释

https://medium.com/@ebuschini/iptables-and-docker-95e2496f0b45


归档时间:

查看次数:

26540 次

最近记录:

6 年,1 月 前