Docker-在已安装的卷上组成集合用户和组 [英] Docker-compose set user and group on mounted volume
问题描述
我正在尝试在docker-compose中挂载一个卷来Apache镜像。问题是,我的Docker中的apache在 www-data:www-data
下运行,而挂载的目录在 root:root 下创建code>。我如何指定挂载目录的用户?
I'm trying to mount a volume in docker-compose to apache image. The problem is, that apache in my docker is run under www-data:www-data
but the mounted directory is created under root:root
. How can I specify the user of the mounted directory?
我试图运行命令 setupApacheRights.sh
。 chown -R www-data:www-data / var / www
,但显示 chown:更改'/ var / www / somefile'的所有权:权限被拒绝
I tried to run command setupApacheRights.sh
. chown -R www-data:www-data /var/www
but it says chown: changing ownership of '/var/www/somefile': Permission denied
services:
httpd:
image: apache-image
ports:
- "80:80"
volumes:
- "./:/var/www/app"
links:
- redis
command: /setupApacheRights.sh
我希望能够指定以下用户它将被安装。有办法吗?
I would prefer to be able to specify the user under which it will be mounted. Is there a way?
推荐答案
首先确定 www-data $ c $的uid c>用户:
$ docker exec DOCKER_CONTAINER_ID id
uid=100(www-data) gid=101(www-data) groups=101(www-data)
然后在您的Docker主机上更改所有者使用uid(在此示例中为100)对已安装目录进行修改:
Then, on your docker host, change the owner of the mounted directory using the uid (100 in this example):
chown -R 100 ./
动态扩展
如果您使用的是 docker-compose
您也可以像这样:
$ docker-compose exec SERVICE_NAME id
uid=100(www-data) gid=101(www-data) groups=101(www-data)
$ chown -R 100 ./
您可以将其放在一个直线上:
You can put that in a one-liner:
$ chown -r $(docker-compose exec SERVICE_NAME id -u) ./
-u
标志只会将 uid
打印到标准输出。
The -u
flag will only print the uid
to stdout.
这篇关于Docker-在已安装的卷上组成集合用户和组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!