這次遇到起 docker nginx 卻無法連線
出現 curl: (56) Recv failure: Connection reset by peer
$ docker run -d -p 80:80 --name myweb nginx
$ curl http://localhost
curl: (56) Recv failure: Connection reset by peer
查了許久才發現是 docker veth 沒有正常 bridge 到 docker network interface
是因為 veth match 到 /lib/systemd/network/80-wired.network 這個設定
而卡在 configuring
可用 networkctl status -a 指令觀察狀態
$ networkctl status -a
● 8: veth23375aa
Link File: n/a
Network File: /lib/systemd/network/80-wired.network
Type: ether
State: degraded (configuring)
Driver: veth
HW Address: 1e:eb:7d:8b:a2:08
MTU: 1500 (min: 68, max: 65535)
QDisc: noqueue
IPv6 Address Generation Mode: eui64
Queue Length (Tx/Rx): 1/1
Auto negotiation: no
Speed: 10Gbps
Duplex: full
Port: tp
Address: fe80::1ceb:7dff:fe8b:a208
DHCP6 Client DUID: DUID-EN/Vendor:0000ab11ac337e4e1d50679b0000
/lib/systemd/network/80-wired.network 內容
ref:
比較 ubuntu 上 docker veth 正常會 match 到 /usr/lib/systemd/network/99-default.link
狀態會是 unmanaged
且 ubuntu 並沒有 80-wired.network 這個設定檔
$ networkctl status -a
● 8: vetheb18eef
Link File: /usr/lib/systemd/network/99-default.link
Network File: n/a
Type: ether
State: n/a (unmanaged)
Driver: veth
...
解決方式:
建立 /etc/systemd/network/20-docker-veth.network 讓 veth 先 match 到並跳過管理
[Match]
Name=veth*
Driver=veth
[Link]
Unmanaged=true
然後重啟 systemd-networkd
sudo systemctl restart systemd-networkd.service