In short: I am trying to mount a host directory in Docker, but then I can not access it from within the container, even if the access permissions look good.
The details:
I am doing
sudo docker run -i -v /data1/Downloads:/Downloads ubuntu bash
and then
ls -al
It gives me:
total 8892
drwxr-xr-x. 23 root root 4096 Jun 18 14:34 .
drwxr-xr-x. 23 root root 4096 Jun 18 14:34 ..
-rwxr-xr-x. 1 root root 0 Jun 18 14:34 .dockerenv
-rwx------. 1 root root 9014486 Jun 17 22:09 .dockerinit
drwxrwxr-x. 18 1000 1000 12288 Jun 16 11:40 Downloads
drwxr-xr-x. 2 root root 4096 Jan 29 18:10 bin
drwxr-xr-x. 2 root root 4096 Apr 19 2012 boot
drwxr-xr-x. 4 root root 340 Jun 18 14:34 dev
drwxr-xr-x. 56 root root 4096 Jun 18 14:34 etc
drwxr-xr-x. 2 root root 4096 Apr 19 2012 home
and a lot more lines like that (I think this is the relevant portion).
If I do
cd /Downloads
ls
the result is
ls: cannot open directory .: Permission denied
The host is Fedora 20, with Docker 1.0.0 and go1.2.2.
Any ideas what is going wrong?
I resolved that issue by using a data container, this also has the advantage of isolating the data from the application layer. You could run it like this:
This tutorial provides a good explanation on the use of data containers.
I had a similar issue, mine was caused by a mismatch between the UID of the host and the UID of the container's user. The fix was to pass the UID of the user as an argument to the docker build and create the container's user with the same UID.
In the DockerFile:
In the build step:
After that, running the container and commands as per the OP gave me the expected result.
It is an selinux issue.
You can temporarily issue
on the host to access or else add an selinux rule by running
I verified that
chcon -Rt svirt_sandbox_file_t /path/to/volume
does work and you don't have to run as a privileged container.This is on :
sudo -s
did the trick for me on MACSee this Project Atomic blog post about Volumes and SELinux for the full story.
Specifically: