1. 程式人生 > 實用技巧 >虛擬機器多了個網絡卡用ethtool -i檢視是veth驅動,是docker 惹得禍

虛擬機器多了個網絡卡用ethtool -i檢視是veth驅動,是docker 惹得禍

當我通過docker run啟動任何容器時,我們得到一個新的veth interface.刪除容器後,應刪除與容器連結的veth介面.但是,有時它會失敗(然後容器啟動出錯):

  1. root@hostname /home # ifconfig | grep veth | wc -l
  2. 53
  3. root@hostname /home # docker run -d -P axibase/atsd -name axibase-atsd-
  4. 28381035d1ae2800dea51474c4dee9525f56c2347b1583f56131d8a23451a84e
  5. 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.
  6. (exit status 1)
  7. root@hostname /home # ifconfig | grep veth | wc -l
  8. 55
  9. root@hostname /home # docker rm -f 2838
  10. 2838
  11. root@hostname /home # ifconfig | grep veth | wc -l
  12. 55

我如何識別哪些介面與現有容器連結,以及如何刪除與已刪除的對手鍊接的額外介面?

這種方式不起作用(通過root):

  1. ifconfig veth55d245e down
  2. brctl delbr veth55d245e
  3. can't delete bridge veth55d245e: Operation not permitted

現在由傳輸流量定義的額外介面(如果沒有活動,則是額外介面).

UPDATE

  1. root@hostname ~ # uname -a
  2. 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
  3. root@hostname ~ # docker info
  4. Containers: 10
  5. Images: 273
  6. Storage Driver: aufs
  7. Root Dir: /var/lib/docker/aufs
  8. Backing Filesystem: extfs
  9. Dirs: 502
  10. Dirperm1 Supported: false
  11. Execution Driver: native-0.2
  12. Logging Driver: json-file
  13. Kernel Version: 3.13.0-53-generic
  14. Operating System: Ubuntu 14.04.2 LTS
  15. CPUs: 8
  16. Total Memory: 47.16 GiB
  17. Name: hostname
  18. ID: 3SQM:44OG:77HJ:GBAU:2OWZ:C5CN:UWDV:JHRZ:LM7L:FJUN:AGUQ:HFAL
  19. WARNING: No swap limit support
  20. root@hostname ~ # docker version
  21. Client version: 1.7.1
  22. Client API version: 1.19
  23. Go version (client): go1.4.2
  24. Git commit (client): 786b29d
  25. OS/Arch (client): linux/amd64
  26. Server version: 1.7.1
  27. Server API version: 1.19
  28. Go version (server): go1.4.2
  29. Git commit (server): 786b29d
  30. OS/Arch (server): linux/amd64
最佳答案 這裡有三個問題:

>啟動單個容器不應該將系統上的veth介面數增加2,因為當Docker建立一個veth對時,該對的一端在容器名稱空間中被隔離,並且在主機中不可見.
>看起來你無法啟動容器:

  1. Error response from daemon: Cannot start container ...

> Docker應該自動清理veth介面.

這些事實讓我懷疑你的環境中存在根本性的錯誤.您能否更新您的問題,詳細說明您正在使用的分發版,哪個核心版本以及哪個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介面:veth介面不是橋接器,所以當然你不能用brctl刪除它.

要刪除veth介面:

  1. # ip link delete <ifname> <="" code="">

檢測“空閒”介面是一個棘手的問題,因為如果你只是看流量,你可能會意外刪除仍在使用但沒有看到太多活動的東西.

我認為你真正想要尋找的是veth介面,其對等體在全域性網路名稱空間中也是可見的.您可以使用these instructions找到veth介面的對等體,然後檢視該介面是否可見,然後刪除其中一個(刪除veth介面也將刪除其對等體)將是一件簡單的事情.