Docker - mkdir read-only file system

后端 未结 2 2311
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 14:36

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:

mkd         


        
2条回答
  •  借酒劲吻你
    2020-12-28 15:06

    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 container's to have persistent storage from the host system.

    In your case, you wanted /storage to be writeable 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//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//data:/data [...]
    

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

提交回复
热议问题