我已经花了好几个小时试图理解为什么docker碰巧在我的机器上无法工作。我正在使用Ubuntu 18.01 Xfce。已使用官方网站安装了docker,并尝试使用docker container run -it -p 8000:80 nginx
命令测试运行映像。第一次运行就可以了,但是只有当我再次尝试时,本地主机才会陷入无尽的加载循环。它仅在我重新启动docker之后才起作用,然后才是第一次。我还尝试将docker.service
文件编辑为:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375
再次根据https://docs.docker.com/install/linux/linux-postinstall/
的指示进行更改。
是否有解决此问题的方法?和操作系统有问题吗?某种冲突问题?如果是这样,有解决办法吗?
更新:
ip addr show docker0
命令在容器运行时显示:
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:4e:4b:8e:af brd ff:ff:ff:ff:ff:ff
inet6 fe80::42:4eff:fe4b:8eaf/64 scope link
valid_lft forever preferred_lft forever
更新2:
通过输入命令sudo docker run -t -i nginx /bin/bash
并阅读tail -f /var/log/syslog
,我有以下几行内容:
Feb 5 11:09:43 unkn0wn27-X550VX dockerd[8188]: time="2020-02-05T11:09:43.010897917+02:00" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.539911] docker0: port 2(vethb213531) entered disabled state
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: vethb213531: Lost carrier
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.541590] veth4234a1c: renamed from eth0
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Network configuration changed, trying to establish connection.
Feb 5 11:09:43 unkn0wn27-X550VX systemd-udevd[9744]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Synchronized to time server 194.40.240.12:123 (194.40.240.12).
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.1724] manager: (veth4234a1c): new Veth device (/org/freedesktop/NetworkManager/Devices/43)
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.641548] audit: type=1107 audit(1580893783.171:310): pid=1164 uid=103 auid=4294967295 ses=4294967295 msg='apparmor="DENIED" operation="dbus_signal" bus="system" path="/org/freedesktop/NetworkManager" interface="org.freedesktop.NetworkManager" member="DeviceAdded" name=":1.13" mask="receive" pid=3643 label="snap.telegram-desktop.telegram-desktop" peer_pid=1280 peer_label="unconfined"
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.641548] exe="/usr/bin/dbus-daemon" sauid=103 hostname=? addr=? terminal=?'
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.644507] audit: type=1107 audit(1580893783.171:311): pid=1164 uid=103 auid=4294967295 ses=4294967295 msg='apparmor="DENIED" operation="dbus_signal" bus="system" path="/org/freedesktop/NetworkManager" interface="org.freedesktop.NetworkManager" member="PropertiesChanged" name=":1.13" mask="receive" pid=3643 label="snap.telegram-desktop.telegram-desktop" peer_pid=1280 peer_label="unconfined"
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.644507] exe="/usr/bin/dbus-daemon" sauid=103 hostname=? addr=? terminal=?'
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.1829] devices added (path: /sys/devices/virtual/net/veth4234a1c, iface: veth4234a1c)
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.1830] device added (path: /sys/devices/virtual/net/veth4234a1c, iface: veth4234a1c): no ifupdown configuration found.
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.653532] IPv6: ADDRCONF(NETDEV_CHANGE): veth4234a1c: link becomes ready
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.653779] docker0: port 2(vethb213531) entered blocking state
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.653784] docker0: port 2(vethb213531) entered forwarding state
Feb 5 11:09:43 unkn0wn27-X550VX networkd-dispatcher[1265]: WARNING:Unknown index 30 seen, reloading interface list
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Network configuration changed, trying to establish connection.
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.1911] device (veth4234a1c): carrier: link connected
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.1934] device (vethb213531): carrier: link connected
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: veth4234a1c: Gained carrier
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: vethb213531: Gained carrier
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Synchronized to time server 194.40.240.12:123 (194.40.240.12).
Feb 5 11:09:43 unkn0wn27-X550VX avahi-daemon[1159]: Interface vethb213531.IPv6 no longer relevant for mDNS.
Feb 5 11:09:43 unkn0wn27-X550VX avahi-daemon[1159]: Leaving mDNS multicast group on interface vethb213531.IPv6 with address fe80::c0e3:82ff:febc:a5c4.
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.746817] docker0: port 2(vethb213531) entered disabled state
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.753883] device vethb213531 left promiscuous mode
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.753893] docker0: port 2(vethb213531) entered disabled state
Feb 5 11:09:43 unkn0wn27-X550VX avahi-daemon[1159]: Withdrawing address record for fe80::c0e3:82ff:febc:a5c4 on vethb213531.
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.3453] devices removed (path: /sys/devices/virtual/net/veth4234a1c, iface: veth4234a1c)
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.3457] devices removed (path: /sys/devices/virtual/net/vethb213531, iface: vethb213531)
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.816316] audit: type=1107 audit(1580893783.343:312): pid=1164 uid=103 auid=4294967295 ses=4294967295 msg='apparmor="DENIED" operation="dbus_signal" bus="system" path="/org/freedesktop/NetworkManager" interface="org.freedesktop.NetworkManager" member="DeviceRemoved" name=":1.13" mask="receive" pid=3643 label="snap.telegram-desktop.telegram-desktop" peer_pid=1280 peer_label="unconfined"
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.816316] exe="/usr/bin/dbus-daemon" sauid=103 hostname=? addr=? terminal=?'
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.3528] device (vethb213531): released from master device docker0
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: veth4234a1c: Lost carrier
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Network configuration changed, trying to establish connection.
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: veth4234a1c: Removing non-existent address: fe80::42:acff:fe11:3/64 (valid forever), ignoring
Feb 5 11:09:43 unkn0wn27-X550VX systemd-networkd[415]: vethb213531: Lost carrier
Feb 5 11:09:43 unkn0wn27-X550VX systemd-timesyncd[994]: Synchronized to time server 194.40.240.12:123 (194.40.240.12).
Feb 5 11:09:43 unkn0wn27-X550VX dockerd[8188]: time="2020-02-05T11:09:43.530168634+02:00" level=warning msg="8f0463438568dab68c318d3fb928d800b9ca6ec99a918bb06bf8aea4886efa48 cleanup: failed to unmount IPC: umount /var/lib/docker/containers/8f0463438568dab68c318d3fb928d800b9ca6ec99a918bb06bf8aea4886efa48/mounts/shm, flags: 0x2: no such file or directory"
我只发现了以下几行:
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.746817] docker0: port 2(vethb213531) entered disabled state
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.753883] device vethb213531 left promiscuous mode
Feb 5 11:09:43 unkn0wn27-X550VX kernel: [ 1992.753893] docker0: port 2(vethb213531) entered disabled state
这行:
Feb 5 11:09:43 unkn0wn27-X550VX NetworkManager[1280]: <info> [1580893783.3528] device (vethb213531): released from master device docker0
不确定是否对我的情况有所帮助。
更新3:
一种解决方法是不断编写命令sudo ip addr add 172.17.0.1/16 dev docker0
。
答案 0 :(得分:0)
问题是Docker没有保留其IPV4地址。
我要做的就是打开/etc/systemd/network/mynet.network
,并添加以下两行:
[Match]
Name=docker0
[Link]
Unmanaged=yes
重新启动systemctl restart systemd-networkd
和systemctl restart docker
。
此解决方案的所有功劳可在以下位置找到:https://vadosware.io/post/a-reliable-fix-to-docker-not-keeping-its-ipv4-address-on-arch/