linux - 如何识别孤立的 veth 接口(interface)以及如何删除它们?

标签 linux docker network-interface

当我通过 docker run 启动任何容器时,我们会得到一个新的 veth interface .删除容器后,与容器链接的veth接口(interface)应该被删除。但是,有时它会失败(通常然后容器以错误启动):

root@hostname /home # ifconfig | grep veth | wc -l
53
root@hostname /home # docker run -d -P  axibase/atsd -name axibase-atsd-
28381035d1ae2800dea51474c4dee9525f56c2347b1583f56131d8a23451a84e
Error response from daemon: Cannot start container 28381035d1ae2800dea51474c4dee9525f56c2347b1583f56131d8a23451a84e: iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 33359 -j DNAT --to-destination 172.17.2.136:8883 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)
root@hostname /home # ifconfig | grep veth | wc -l
55
root@hostname /home # docker rm -f 2838
2838
root@hostname /home # ifconfig | grep veth | wc -l
55

如何识别哪些接口(interface)与现有容器链接,以及如何删除与已删除的容器链接的额外接口(interface)?

这种方式不起作用(通过root):

ifconfig veth55d245e down
brctl delbr veth55d245e
can't delete bridge veth55d245e: Operation not permitted

现在由传输流量定义的额外接口(interface)(如果没有事件,则为额外接口(interface))。

更新

root@hostname ~ # uname -a
Linux hostname 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

root@hostname ~ # docker info
Containers: 10
Images: 273
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 502
 Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-53-generic
Operating System: Ubuntu 14.04.2 LTS
CPUs: 8
Total Memory: 47.16 GiB
Name: hostname
ID: 3SQM:44OG:77HJ:GBAU:2OWZ:C5CN:UWDV:JHRZ:LM7L:FJUN:AGUQ:HFAL
WARNING: No swap limit support

root@hostname ~ # docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64

最佳答案

这里有三个问题:

  1. 启动单个容器不应将系统上的 veth 接口(interface)数量增加 2,因为当 Docker 创建 veth 对时, pair 在容器命名空间中是隔离的,对宿主是不可见的。

  2. 您似乎无法启动容器:

    Error response from daemon: Cannot start container ...
    
  3. Docker 应该会自动清理 veth 接口(interface)。

这些事实让我怀疑您的环境存在根本性的问题。您能否详细说明您使用的发行版、内核版本和 Docker 版本的详细信息?

How I can identify which interfaces are linked with existing containers, and how I can remove extra interface which was linked with removed contrainers?

关于手动删除 veth 接口(interface): veth 接口(interface)不是桥梁,所以你当然不能用 brctl.

删除一个veth接口(interface):

# ip link delete <ifname>

检测“空闲”接口(interface)是一个更棘手的问题,因为如果您只查看流量,您可能会意外删除仍在使用但没有看到太多事件的内容。

我认为您真正想要寻找的是 veth 接口(interface),其对等点 also 在全局网络命名空间中可见。您可以使用 these instructions 找到 veth 接口(interface)的对等点,然后查看该接口(interface)是否可见,然后删除一个或另一个(删除 veth 接口(interface)也将删除其对等点),这将是一件简单的事情。

关于linux - 如何识别孤立的 veth 接口(interface)以及如何删除它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31989426/

相关文章:

php - 为 Zend_Service_Amazon_S3 选择不同的网络接口(interface)

docker - 如何使用 DockerProvider 服务修复 windows server 2019 中的 'Cookie file/var/lib/rabbitmq/.erlang.cookie must be accessible by owner only' 错误

linux - 需要为网络接口(interface)创建一个 monit cfg

linux - ip_len 设置为非常大的值

linux - 为什么我不能在 bash 中回显 "!"?

asp.net - 无法运行kubernetes部署

amazon-web-services - 将集群加入主节点时,Kubernetes 工作节点连接被拒绝

c - 从c中的特定接口(interface)发送数据包

linux - Apache 未在 CentOS 7 服务器上运行

c - 无法计算Linux内核执行C语言编写的hello world程序所花费的时间