docker挂载centos主机目录,访问相应的文件出现Cannot open: Permission denied的权限访问问题。

  1. [root@localhost software]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. docker.io/centos latest 1e1148e4cc2c 2 months ago 202 MB
  4. [root@localhost software]# docker run -i -t -v /root/software/:/mnt/software/ 1e1148e4cc2c /bin/bash
  5. [root@aba1f4fa9d9a /]# cd /mnt/software/
  6. [root@aba1f4fa9d9a software]# ls
  7. ls: cannot open directory .: Permission denied
  8. [root@aba1f4fa9d9a software]#

网上查看原因是centos7中的安全模块selinux把权限禁掉了,解决办法很麻烦。通过查找资料,找到了一个简单的解决办法:挂载的时候加上--privileged=true就可以了

  1. [root@localhost software]# docker run -i -t -v /root/software/:/mnt/software/ --privileged=true 1e1148e4cc2c /bin/bash
  2. [root@1a286fc4bdf6 /]# cd /mnt/software/
  3. [root@1a286fc4bdf6 software]# ls
  4. apache-tomcat-7.0.92.tar.gz
  5. [root@1a286fc4bdf6 software]#