Reputation: 3619
I have been trying to share data between my host and docker container. I am using this command to mount data volume:
sudo docker run -it -v /home/peeyush/Docker/docker/:/opt/test/:rw ubuntu /bin/bash
Now, when I run docker and try to access /opt/test/, it says I don't have the permission. But I have already specified permission as read-write and I am root. Here is the output:
root@d61b3bfe0aab:/# ls /opt/test/
ls: cannot open directory /opt/test/: Permission denied
Any idea what am I doing wrong here?
Update: Here is the output of ls -al /home/peeyush/Docker/docker:
[peeyush@localhost docker]$ ls -al /home/peeyush/Docker/docker/
total 308
drwxrwxr-x. 29 peeyush peeyush 4096 Feb 24 14:14 .
drwxrwxr-x. 5 peeyush peeyush 4096 Feb 23 15:38 ..
drwxrwxr-x. 5 peeyush peeyush 4096 Feb 23 11:53 api
-rw-rw-r--. 1 peeyush peeyush 28898 Feb 23 11:53 AUTHORS
drwxrwxr-x. 4 peeyush peeyush 4096 Feb 23 11:53 builder
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 builtins
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 13:36 bundles
-rw-rw-r--. 1 peeyush peeyush 61942 Feb 23 11:53 CHANGELOG.md
drwxrwxr-x. 11 peeyush peeyush 4096 Feb 23 11:53 contrib
-rw-rw-r--. 1 peeyush peeyush 13305 Feb 23 11:53 CONTRIBUTING.md
drwxrwxr-x. 5 peeyush peeyush 4096 Feb 23 11:53 daemon
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 docker
-rw-rw-r--. 1 peeyush peeyush 5423 Feb 24 14:14 Dockerfile
-rw-rw-r--. 1 peeyush peeyush 16 Feb 23 11:53 .dockerignore
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 dockerinit
drwxrwxr-x. 5 peeyush peeyush 4096 Feb 23 11:53 docs
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 engine
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 events
drwxrwxr-x. 8 peeyush peeyush 4096 Feb 24 14:14 .git
-rw-rw-r--. 1 peeyush peeyush 489 Feb 23 11:53 .gitignore
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 graph
lrwxrwxrwx. 1 peeyush peeyush 7 Feb 23 11:53 hack -> project
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 11:53 image
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 11:53 integration
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 integration-cli
-rw-rw-r--. 1 peeyush peeyush 10763 Feb 23 11:53 LICENSE
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 links
-rw-rw-r--. 1 peeyush peeyush 7171 Feb 23 11:53 .mailmap
-rw-rw-r--. 1 peeyush peeyush 18599 Feb 23 11:53 MAINTAINERS
-rw-rw-r--. 1 peeyush peeyush 3400 Feb 23 11:53 Makefile
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 nat
-rw-rw-r--. 1 peeyush peeyush 638 Feb 23 11:53 NOTICE
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 opts
drwxrwxr-x. 39 peeyush peeyush 4096 Feb 23 11:53 pkg
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 11:53 project
-rw-rw-r--. 1 peeyush peeyush 10624 Feb 23 11:53 README.md
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 11:53 registry
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 runconfig
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 trust
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 utils
drwxrwxr-x. 3 peeyush peeyush 4096 Feb 23 11:53 vendor
-rw-rw-r--. 1 peeyush peeyush 10 Feb 23 11:53 VERSION
drwxrwxr-x. 2 peeyush peeyush 4096 Feb 23 11:53 volumes
And of ls -al /opt/:
root@d61b3bfe0aab:/# ls -al /opt/
total 12
drwxr-xr-x. 3 root root 4096 Feb 25 06:22 .
drwxr-xr-x. 21 root root 4096 Feb 25 06:58 ..
drwxrwxr-x. 29 1000 1000 4096 Feb 24 08:44 test
Thanks.
Upvotes: 0
Views: 153
Reputation: 319
Using a distro with SELinux? You can try turning it to passive (setenforce 0) or try a :Z/:z at the end of the -v command like (/home/peeyush/Docker/docker:/opt/test:Z)
Upvotes: 2
Reputation: 2981
Would be interested to see if it works without the trailing '/'s on the directory paths, as I have never used them and never had this issue.
sudo docker run -it -v /home/peeyush/Docker/docker:/opt/test ubuntu /bin/bash
Upvotes: 0