lxd容器内docker无法启动,报错open /proc/sys/net/ipv4/ip_forward: read-only file system

问题出现场景

在lxd容器中创建了docker容器,有一天所有lxd容器内的docker容器全都起不来;启动时报错

root@bb:~# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2021-01-27 20:20:21 CST; 52s ago
     Docs: https://docs.docker.com
  Process: 435 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
 Main PID: 435 (code=exited, status=1/FAILURE)

Jan 27 20:20:21 bb systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Jan 27 20:20:21 bb systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Jan 27 20:20:21 bb systemd[1]: Stopped Docker Application Container Engine.
Jan 27 20:20:21 bb systemd[1]: docker.service: Start request repeated too quickly.
Jan 27 20:20:21 bb systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 27 20:20:21 bb systemd[1]: Failed to start Docker Application Container En

查看日志详情:

root@bb:~# sudo journalctl -xe

-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit docker.service has begun starting up.
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.784691543+08:00" level=info msg="systemd-resolved is running, so using resolvconf: /run/systemd/resolve/resolv.conf"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787316279+08:00" level=info msg="parsed scheme: \"unix\"" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787383289+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787547821+08:00" level=info msg="parsed scheme: \"unix\"" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787583664+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787577781+08:00" level=info msg="ccResolverWrapper: sending new addresses to cc: [{unix:///run/containerd/containerd.sock 0  <nil>}]" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787636606+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787714113+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc42007f440, CONNECTING" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787750049+08:00" level=info msg="ccResolverWrapper: sending new addresses to cc: [{unix:///run/containerd/containerd.sock 0  <nil>}]" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787786012+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.787876910+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc4207f54e0, CONNECTING" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.788110267+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc42007f440, READY" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.788142830+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc4207f54e0, READY" module=grpc
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.792378731+08:00" level=error msg="'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support l
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.795697602+08:00" level=error msg="AUFS was not found in /proc/filesystems" storage-driver=aufs
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.798731718+08:00" level=error msg="'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support l
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.835798600+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.836420988+08:00" level=warning msg="Your kernel does not support swap memory limit"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.836574929+08:00" level=warning msg="Your kernel does not support cgroup rt period"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.836612848+08:00" level=warning msg="Your kernel does not support cgroup rt runtime"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.836650679+08:00" level=warning msg="Your kernel does not support cgroup blkio weight"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.836687231+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.838965475+08:00" level=info msg="Loading containers: start."
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.842786432+08:00" level=warning msg="Running modprobe nf_nat failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.846767605+08:00" level=warning msg="Running modprobe xt_conntrack failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() cou
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.931682527+08:00" level=warning msg="Enabling IP forwarding failed: open /proc/sys/net/ipv4/ip_forward: read-only file system"
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.933652825+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
Jan 27 20:21:40 bb dockerd[626]: Error starting daemon: Error initializing network controller: error obtaining controller instance: Enabling IP forwarding failed: open /proc/sys/net/ipv4/ip_forward: read-only file
Jan 27 20:21:40 bb dockerd[626]: time="2021-01-27T20:21:40.934417502+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
Jan 27 20:21:40 bb systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Jan 27 20:21:40 bb systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 27 20:21:40 bb systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support

上面日志中有一个关键错误语句:
controller: error obtaining controller instance: Enabling IP forwarding failed: open /proc/sys/net/ipv4/ip_forward: read-only file

得出问题应该是该文件不能修改导致的,查询宿主机文件内容,发现该文件内容为0,要改成1(原因参考:https://blog.csdn.net/li_101357/article/details/78415461)

解决办法

在宿主机中修改/proc/sys/net/ipv4/ip_forward内容为1
echo 1 > /proc/sys/net/ipv4/ip_forward
注意:将此属性设置为0时,使用sudo设置不成功时,切换到root可以修改;

修改完成后重启lxd容器,发现docker起来了。

LXCLinux Containers)和LXDLinux Container Daemon)是一种轻量级虚拟化技术,常用于在Linux系统中创建和管理容器。以下是一些常用的LXC/LXD配置: 1. 安装LXD:使用适合你的Linux发行版的包管理工具进行安装。 2. 初始化LXD:运行`sudo lxd init`命令来初始化LXD。在初始化过程中,你可以设置默认的存储池、网络设置、镜像源等。 3. 创建容器:使用`lxc launch`命令创建一个新容器。例如,要创建一个名为"mycontainer"的容器,可以运行`lxc launch images:ubuntu/20.04 mycontainer`。 4. 启动和停止容器:使用`lxc start`命令启动容器,例如`lxc start mycontainer`。使用`lxc stop`命令停止容器,例如`lxc stop mycontainer`。 5. 进入容器:使用`lxc exec`命令可以在容器内执行命令。例如,要在"mycontainer"容器内执行`ls`命令,可以运行`lxc exec mycontainer -- ls`。 6. 管理容器配置:使用`lxc config`命令可以管理容器的配置。例如,要查看容器IP地址,可以运行`lxc config show mycontainer | grep ipv4.address`。 7. 管理网络:使用`lxc network`命令可以管理LXD网络。例如,要列出所有网络,可以运行`lxc network list`。 8. 导出和导入容器:使用`lxc export`命令可以将容器导出到一个文件。例如,要将"mycontainer"导出到"mycontainer.tar.gz"文件,可以运行`lxc export mycontainer mycontainer.tar.gz`。使用`lxc import`命令可以从导出文件导入一个容器。 这些是LXC/LXD的一些常用配置,还有其他更高级的配置和功能可供探索。你可以使用`lxc --help`命令或参考LXD的官方文档来获取更多详细信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值