Reputation: 763
I am trying to learn Docker volumes, and I am using centos:latest
as my base image. When I try to run a Docker command, I am unable to access the attached volume inside the container:
Command:
sudo docker run -it --name test -v /home/user/Myhostdir:/mydata centos:latest /bin/bash
Error:
[user@0bd1bb78b1a5 mydata]$ ls
ls: cannot open directory .: Permission denied
When I try to ls
to find the folder permission, it says 1001. What's happening, and how can to solve this?
drwxrwxr-x. 2 1001 1001 38 Jun 2 23:12 mydata
My local machine:
[user@xxx07012 Myhostdir]$ pwd
/home/user/Myhostdir
[user@swathi07012 Myhostdir]$ ls -al
total 12
drwxrwxr-x. 2 user user 38 Jun 2 23:12 .
drwx------. 18 user user 4096 Jun 2 23:11 ..
-rw-rw-r--. 1 user user 15 Jun 2 23:12 text.2.txt
-rw-rw-r--. 1 user user 25 Jun 2 23:12 text.txt
Upvotes: 0
Views: 270
Reputation: 51165
This is partially a Docker issue, but mostly an SELinux issue. I am assuming you are running an old 1.x
version of Docker.
You have a couple of options. First, you could take a look at this blog post to understand the issue a bit more and possibly use the fix mentioned there.
Or you could just upgrade to a newer version of Docker. I tested mounting a simple volume on Docker version 18.03.1-ce:
docker run -it --name test -v /home/chris/test:/mydata centos:latest /bin/bash
[root@bfec7af20b99 /]# cd mydata/
[root@bfec7af20b99 mydata]# ls
test.txt.txt
[root@bfec7af20b99 mydata]# ls -l
total 0
-rwxr-xr-x 1 root root 0 Jun 3 00:40 test.txt.txt
Upvotes: 1