简体   繁体   English

在docker中已装入卷中的权限被拒绝

[英]Permission denied in mounted volume in docker

I'm mounting a volume from my local host in a docker container using docker-compose (added the volumes entry id docker-compose.yml) 我正在使用docker-compose从Docker容器中的本地主机上安装一个卷(添加了volumes条目id docker-compose.yml)

This works well, but when I try to run py.test I get permission errors: 这很好用,但是当我尝试运行py.test时,我得到权限错误:

OSError: [Errno 13] Permission denied: '/foo/bar/.coverage' etc OSError: [Errno 13] Permission denied: '/foo/bar/.coverage'

Also, when I try to create the .coverage dir when I'm logged in to the container I get: 此外,当我尝试创建.coverage目录时,我登录到容器,我得到:

mkdir .coverage
mkdir: cannot create directory '.coverage': Permission denied

Any ideas on how to solve this? 关于如何解决这个问题的任何想法?

You can do anything (like a volume mount) in the docker container as long as the Docker itself has the right permission. 只要Docker本身具有正确的权限,您就可以在docker容器中执行任何操作(如卷装入)。 You should exec your container using following: 您应该使用以下内容执行容器:

docker exec -it -u 0 Container_NAME /bin/bash docker exec -it -u 0 Container_NAME / bin / bash

And then execute py.test, I just hope you're not doing su - to some user within py.test 然后执行py.test,我只希望你没有对py.test中的某个用户做su

这可能是由于该目录上的文件上下文,尝试将其更改为“沙盒”文件:

chcon -Rt svirt_sandbox_file_t /foo/bar/

Got the same issue and fixed it by adding a chmod -R 777 in my Dockerfile (adapt 777 to your permissions but you need a read/write) on the root folder of my test package (foo/bar/ in your case). 得到了同样的问题并通过在我的Dockerfile中添加chmod -R 777来修复它(在您的测试包的根文件夹中调整777到你的权限,但你需要读/写)(在你的情况下为foo / bar /)。 I made it recursive because I run my test coverage in my sub-folders as well. 我使它递归,因为我也在我的子文件夹中运行我的测试覆盖率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM