在docker中访问主机目录时拒绝权限 [英] Permission denied on accessing host directory in docker

查看:585
本文介绍了在docker中访问主机目录时拒绝权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:我试图在Docker中安装主机目录,但是即使访问权限看起来不错,我也无法从容器中访问它。



详细信息:



我在做

  sudo docker运行-i -v / data1 /下载:/下载ubuntu bash 

然后

  ls -al 

它给了我:

 总计8892 
drwxr-xr -X。 23根根4096 6月18日14:34。
drwxr-xr-x。 23根根4096 6月18日14:34 ..
-rwxr-xr-x。 1根根0 6月18日14:34 .dockerenv
-rwx ------。 1根根9014486 Jun 17 22:09 .dockerinit
drwxrwxr-x。 18 1000 1000 12288 Jun 16 11:40下载
drwxr-xr-x。 2根根4096 Jan 29 18:10 bin
drwxr-xr-x。 2根根4096 Apr 19 2012 boot
drwxr-xr-x。 4根根340 6月18日14:34 dev
drwxr-xr-x。 56根根4096 Jun 18 14:34 etc
drwxr-xr-x。 2根根4096 Apr 19 2012首页

和更多的行(我认为这是相关部分)。



如果我执行

  cd / Downloads 
ls

结果是

  ls:无法打开目录。权限被拒绝

主机是Fedora 20,与Docker 1.0.0和go1.2.2。



任何想法出了什么问题?

解决方案

selinux问题。



您可以暂时发布

  su -c主机上的setenforce 0

通过运行

$来添加selinux规则b
$ b

  chcon -Rt svirt_sandbox_file_t / path / to / volume 


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?

解决方案

It is an selinux issue.

You can temporarily issue

su -c "setenforce 0"

on the host to access or else add an selinux rule by running

chcon -Rt svirt_sandbox_file_t /path/to/volume

这篇关于在docker中访问主机目录时拒绝权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆