84

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? Commented Sep 26, 2018 at 22:18
  • 1
    read-only file system might indicate hdd failure. Happened to me, changed hdd and everything worked. 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
  • 6
    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. " Commented Jul 11, 2020 at 20:58

5 Answers 5

164

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/

Sign up to request clarification or add additional context in comments.

6 Comments

Re-install docker from official repository solved this problem for me too. Here is additional information about this workaround.
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?
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 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)
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."
|
24

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. 🙌🏽

Comments

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

Comments

0

If you're working with output files that you're saving to your file system using bind mounts, it's important to be careful about the path you're using.

Ensure that the path has the proper permissions. For example, avoid using root paths unless absolutely necessary.

It's generally safer to use a relative path from your execution directory. If you must use a root path, make sure it is accessible and has write permissions to avoid issues when saving files.

Simple Example:

docker run -v "$(shell pwd):/src" image-xxx some-cmd --output=./somedir

Comments

-3

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

ex.:

docker run --privileged -i --name master --hostname k8s-master -d ubuntu:20.04

1 Comment

Actually I have privileged in my docker-compose.yaml to solve another problem, but this doesn't work for this particular problem.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.