79

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.

Jamie Brunton
  • 893
  • 1
  • 6
  • 6
  • How are you running the container? Is the process inside the container running as root or a normal user? – Motakjuq Sep 26 '18 at 22:18
  • 1
    `read-only file system` might indicate hdd failure. Happened to me, changed hdd and everything worked. – Kevin Kopf Sep 27 '18 at 01: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! – Jamie Brunton Sep 27 '18 at 08: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. – Jamie Brunton Sep 27 '18 at 08:35
  • 5
    This is because the docker snap may only write files under $HOME. See https://snapcraft.io/install/docker/ubuntu : "This build requires all files that Docker uses, such as dockerfiles, to be in $HOME. " – masterxilo Jul 11 '20 at 20:58
  • For me changing the volumes property in the yml file to begin with "/home/OTHER_FOLDER_NAMES" did the trick. – Zafar Nasim May 18 '21 at 06:18

3 Answers3

156

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/

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Attila Szili
  • 1,561
  • 1
  • 5
  • 2
  • 1
    Re-install docker from official repository solved this problem for me too. [Here](https://github.com/Microsoft/vscode-docker/issues/749#issuecomment-456896655) is additional information about this workaround. – Maxim Apr 02 '19 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? – Mazhar Zandsalimi Aug 02 '19 at 17:06
  • 9
    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 Feb 26 '20 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 Jul 15 '21 at 07:36
  • 09.2021 Worked for me on Ubuntu 20 – heyjohnnyfunt Sep 01 '21 at 11:29
  • From https://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 Apr 14 '23 at 13:18
19

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.

berto
  • 8,215
  • 4
  • 25
  • 21
-1

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

ex.:

docker run --privileged -i --name master --hostname k8s-master -d ubuntu:20.04
Marcelo Guedes
  • 1,419
  • 11
  • 10
  • Actually I have privileged in my docker-compose.yaml to solve another problem, but this doesn't work for this particular problem. – Hugh Barnard Aug 17 '23 at 14:58