80

After freshly installing Ubuntu 18 I am receiving the following error when trying to launch a docker container that has a bind to a LVM (ext4) partition:

mkdir /storage: read-only file system

I have tried reinstalling the OS, reinstalling Docker and forcing the drive to mount as RW (everything that isn't docker can write to the drive).

The directory that is being bound is currently set to 777 permissions.

There seems to be almost no information available for this error.

6
  • How are you running the container? Is the process inside the container running as root or a normal user?
    – Motakjuq
    Commented Sep 26, 2018 at 22:18
  • 1
    read-only file system might indicate hdd failure. Happened to me, changed hdd and everything worked.
    – Kevin Kopf
    Commented Sep 27, 2018 at 1:00
  • The process is running as a normal user, the permissions for /storage are 777 though, this should allow any user to write to it. How could I confirm HDD failure? Up until this point, the machine has been perfectly fine and functioning as a Windows docker host! Commented Sep 27, 2018 at 8:18
  • It is probably worth mentioning that if I sign into ssh as a normal user, I am able to create directories fine so something with the docker configuration appears to be wrong. Commented Sep 27, 2018 at 8:35
  • 5
    This is because the docker snap may only write files under $HOME. See snapcraft.io/install/docker/ubuntu : "This build requires all files that Docker uses, such as dockerfiles, to be in $HOME. "
    – masterxilo
    Commented Jul 11, 2020 at 20:58

4 Answers 4

162

Try removing docker from snap and reinstalling it following the official docker steps.

Remove docker from snap:

snap remove docker

Then remove the docker directory and the old version:

rm -R /var/lib/docker

sudo apt-get remove docker docker-engine docker.io

Install official docker: https://docs.docker.com/install/linux/docker-ce/ubuntu/

6
  • 1
    Re-install docker from official repository solved this problem for me too. Here is additional information about this workaround.
    – Maxim
    Commented Apr 2, 2019 at 14:41
  • Thanks for the tip on how snap messes up docker. Just one thing though, if -r and -R are the same for rm, why bother with the capital one?
    – Maz
    Commented Aug 2, 2019 at 17:06
  • 14
    So basically if you just "follow" the ubuntu suggestion how to install docker you end up with a completely unusable install of docker? Cool...
    – omnibrain
    Commented Feb 26, 2020 at 20:36
  • @omnibrain No, it's not completely unusable. docker run hello-world is working. ;) ...probably because it does not use volumes (this is of course a disappointing situation)
    – The Bndr
    Commented Jul 15, 2021 at 7:36
  • 1
    From snapcraft.io/install/docker/ubuntu : "This build can only access files in the home directory. So Dockerfiles and all other files used in commands like docker build, docker save and docker load need to be in $HOME."
    – Dave
    Commented Apr 14, 2023 at 13:18
21

Update 01/2021: while still pretty cool, Snaps don't always work. Specifically with the Docker Snap, it didn't work for Swarm mode, so I ditched it and installed Docker the recommended way.

Snaps are actually pretty cool, IMO, and think it's beneficial to run Docker within a Snap than installing it directly on the system. The fact that you're getting a read-only permissions error is a good thing. It means that a rogue container isn't able to wreak havoc on your base OS. That said, how to fix your issue.

The reason that this is coming up is that Snaps will expose the host OS as read-only so that Docker can see the host's files, but not modify them (hence the permission denied error). But there is a directory that the Docker Snap can write to: /var/snap/docker. Actually, a better directory that snap can write to is /home. I created /home/docker for containers to have persistent storage from the host system.

In your case, you wanted /storage to be writable by Docker containers. I had a very similar use-case, which led me to this SO post. I solved this by mounting my storage within the docker snap directory /home/docker; the easiest example simply being a directory on the same filesystem:

mkdir -p /home/docker/<container name>/data

In my case, I created a ZFS dataset at the location above instead of simply mkdir'ing a directory.

Then, the container I ran could write to that with something like:

docker run -ti -v /home/docker/<container name>/data:/data [...]

Now you have the best of both worlds: Docker running in a contained Snap environment and persistent storage. 🙌🏽

0
0

if you have currently have this problem on Windows with Docker Desktop, try downgrading to Docker Desktop version 4.24.2:

  1. uninistall docker desktop
  2. install 4.24.2: https://docs.docker.com/desktop/release-notes/#4242
  3. delete C:\Users\xxxxxxx\AppData\Roaming\Docker if after restart docker desktop dows not start (happened in my case)

issue: https://github.com/docker/for-win/issues/13947

-3

you can create/run your container with --privileged:

ex.:

docker run --privileged -i --name master --hostname k8s-master -d ubuntu:20.04
1
  • Actually I have privileged in my docker-compose.yaml to solve another problem, but this doesn't work for this particular problem. Commented Aug 17, 2023 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.