10

I'm trying to mount a directory in Docker run:

docker run --restart always -t -v /home/dir1/dir2/dir3:/dirX --name [...]

But I get the error:

error while creating mount source path '/home/dir1/dir2/dir3': mkdir /home/dir1/dir2/dir3: permission denied.

All the directories exist for sure, and the strange thing is when trying to mount dir2 and not dir3 it is working ok:

docker run --restart always -t -v /home/dir1/dir2/:/dirX --name [...]   # THIS IS WORKING

All the directories ('dir2' and 'dir3') have the same permissions: drwxr-x---

Any suggestions on what might be the problem? why one is working and the other don't? Thanks

Izik
  • 746
  • 1
  • 9
  • 25
  • You really have `/home/dir1/dir2/dir3`? Docker is trying to setup it for you means it think the folder not exist... – atline Dec 10 '20 at 06:14
  • Yes all the directories in the path do exists, including the last one – Izik Dec 10 '20 at 09:05
  • Please include the output of `ls -al /home/dir1/dir2/dir3`, describe how the docker engine is installed and running, and describe the host (including whether selinux is enabled). – BMitch Dec 10 '20 at 12:51
  • A similar error to this one which ends with the message "read-only file system" can be caused by installing docker as a snap. – Sam Sep 14 '22 at 17:52

1 Answers1

1

Check the permission for the folder you're trying to mount docker with ls -la, you might need to modify the permissons with chmod.

If you don't want to modify permissions, just add sudoto the beggining of the command.

sudo docker run --restart always -t -v /home/dir1/dir2/dir3:/dirX --name [...]

Thales Kenne
  • 2,705
  • 1
  • 12
  • 26
  • 1
    The permission is "drwxr-x---"(as I wrote in the question) which is enough to mount to dir2, but no success for dir1. Unfortunately, I'm working on a server where I can't change directories permissions, or use sudo (anyway the docker is with root permissions, but root permissions on the server are limited intentionally), or even create a new directory – Izik Dec 10 '20 at 09:16