Reputation: 948
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
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
Reputation: 16
I faced the same issue earlier and here is what I done.
chown
if needed (I think at least user in "docker" group able to access it)privileged
option--user 0:0
Upvotes: 0
Reputation: 11
I have 2 suggestions to troubleshoot;
--privileged
like docker run --restart always --privileged -t -v /home/dir1/dir2/dir3:/dirX --name [...]
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
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 sudo
to the beggining of the command.
sudo docker run --restart always -t -v /home/dir1/dir2/dir3:/dirX --name [...]
Upvotes: -1