Izik
Izik

Reputation: 948

Docker run "error while creating mount source path '[...]': mkdir [...]: permission denied"

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

Upvotes: 18

Views: 33501

Answers (4)

techmagister
techmagister

Reputation: 1358

First , check whether directory exists and accesible to the docker process

ls -ld /directory_name/sub_directory

If not or not available, create the directoty using sudo mkdir

Update the ownership and permisions

sudo chown -R $USER:$USER /directory_name/sub_directory
sudo chmod -R 775 /directory_name/sub_directory

Remove all tangling docker images

docker image prune

Remove all tangling docker volumes

docker volume prune

Restart docker engine

Upvotes: 0

C.Andrew
C.Andrew

Reputation: 16

I faced the same issue earlier and here is what I done.

  1. Check the owner of the directory and use chown if needed (I think at least user in "docker" group able to access it)
  2. add privileged option
  3. Specify the root user (or any other user you running the docker) by --user 0:0

Upvotes: 0

H. Sinan Alioglu
H. Sinan Alioglu

Reputation: 11

I have 2 suggestions to troubleshoot;

  1. Try using --privileged like docker run --restart always --privileged -t -v /home/dir1/dir2/dir3:/dirX --name [...]
  2. Try adding z or Z while mounting like docker run --restart always -t -v /home/dir1/dir2/dir3:/dirX:z --name [...]

Additionally you can check for hidden restrictions with getfacl /home/dir1/dir2/dir3

My guess is docker group or the user you're trying doesn't have enough permissions for /home/dir1/dir2/dir3

Upvotes: 1

Thales Kenne
Thales Kenne

Reputation: 2922

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 [...]

Upvotes: -1

Related Questions