Docker "mkdir /var/lib/docker: read-only file system" in CI
The daemon stores images, layers, and container state under its data-root (default /var/lib/docker). If that path lands on a read-only mount - a read-only root filesystem, a remounted volume, or a misconfigured data-root - the daemon cannot create directories and fails with read-only file system.
What this error means
A pull, build, or run fails with Error response from daemon: mkdir /var/lib/docker/...: read-only file system. The data-root is on a read-only mount.
docker
Error response from daemon: error creating overlay mount to /var/lib/docker/overlay2/.../merged: mkdir /var/lib/docker/overlay2: read-only file systemCommon causes
A read-only root filesystem
On hardened or immutable hosts, /var/lib/docker may sit on a read-only root, blocking writes.
A misconfigured or remounted data-root
A data-root pointed at a read-only volume cannot store image and container data.
How to fix it
Point data-root at a writable path
- Set the daemon data-root to a writable mount and restart.
daemon.json
# /etc/docker/daemon.json
{ "data-root": "/mnt/docker-data" }
# then: sudo systemctl restart dockerRemount the data-root read-write
- If the existing mount should be writable, remount it rw.
Terminal
mount | grep /var/lib/docker
sudo mount -o remount,rw /var/lib/dockerHow to prevent it
- Keep the daemon data-root on a writable mount.
- Avoid placing /var/lib/docker on a read-only root.
- Verify mount options when provisioning Docker hosts.
Related guides
Docker Daemon Fails to Start - "unable to configure ... invalid daemon.json" in CIFix dockerd failing to start in CI - "unable to configure the Docker daemon ... invalid character" from a mal…
Docker "no space left on device" during build in CIFix the Docker "no space left on device" build error in CI by reclaiming disk from accumulated layers and bui…
Docker "error mounting ... operation not permitted" - Fix Mount Failures in CIFix Docker "OCI runtime create failed: error mounting ... operation not permitted" in CI - a bind mount denie…