我有一个在只读根分区上运行 Ubuntu 16.04.6 LTS 的 Raspberry Pi 3。现在我尝试启动一个 docker 守护进程。但重启后它说:
ubuntu@z11:~$ docker info
Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
尝试重新启动 docker 守护程序时,我得到:
ubuntu@z11:~$ sudo systemctl daemon-reload
ubuntu@z11:~$ sudo systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
这是
systemctl status docker.service
的输出:● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Thu 2016-02-11 17:28:26 CET; 14s ago
Docs: https://docs.docker.com
Process: 1620 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 1620 (code=exited, status=1/FAILURE)
Feb 11 17:28:24 z11 systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Feb 11 17:28:24 z11 systemd[1]: Failed to start Docker Application Container Engine.
Feb 11 17:28:24 z11 systemd[1]: docker.service: Unit entered failed state.
Feb 11 17:28:24 z11 systemd[1]: docker.service: Failed with result 'exit-code'.
Feb 11 17:28:26 z11 systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Feb 11 17:28:26 z11 systemd[1]: Stopped Docker Application Container Engine.
Feb 11 17:28:26 z11 systemd[1]: docker.service: Start request repeated too quickly.
Feb 11 17:28:26 z11 systemd[1]: Failed to start Docker Application Container Engine.
Feb 11 17:28:26 z11 systemd[1]: docker.service: Unit entered failed state.
Feb 11 17:28:26 z11 systemd[1]: docker.service: Failed with result 'start-limit-hit'.
这是我的/etc/fstab,带有只读根分区和读写/var/lib/docker:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat ro 0 0
/dev/mmcblk0p2 / ext4 noatime,ro 0 0
/dev/mmcblk0p3 none swap sw 0 0
/dev/mmcblk0p4 /var/lib/docker ext4 noatime,rw 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=50m 0 0
tmpfs /var/log/apache2 tmpfs defaults,noatime,size=10m 0 0
tmpfs /var/lib/sudo tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0
tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=30m 0 0
从
ro
更改根分区时至rw
, docker 在重启系统后运行良好。我怎样才能让它在保持根分区只读的情况下运行 docker?
docker 是否需要写入其他文件或目录?
最佳答案
我想知道 mount
的结果是什么好像 ?
我的情况和你的有点不同。
就我而言,我在根覆盖文件系统上运行 docker daemon 时遇到了同样的问题。
我希望我的解决方案也可以帮助您或其他任何人。
根据指导方针,
http://docs.docker.jp/engine/userguide/storagedriver/selectadriver.html ,
docker 不能在覆盖支持文件系统上运行。
但幸运的是,它可以在覆盖文件系统之上的 tmpfs 上运行。
这是我的环境:
- Ubuntu Server 19.10
- Raspberry PI 4B
- Using overlayroot for making the root overlayed on a read-only filesystem
我的解决方案是:
sudo mount -t tmpfs tmpfs /var/lib/docker
after boot (edited/etc/fstab
may not work for overlayroot)- restart docker with
sudo systemctl restart docker
如果 Step2 失败,只需等待几秒钟并重试(Step1 似乎无法立即工作)。
我还发现,如果重复 Step1 两次以上,Step2 可以立即执行。抱歉,我无法解释为什么。
关于docker - 如何在只读主机文件系统上运行 docker daemon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731258/