简体   繁体   English

Docker --volumes-from权限

[英]Docker --volumes-from permissions

I'm very new to Docker so I might be missing something, my data volume folder has root as owner. 我是Docker的新手,所以我可能会缺少一些东西,我的数据卷文件夹的所有者为root

Here is what I do (using the nginx reverse proxy): 这是我的工作(使用nginx反向代理):

# Data volume container
docker create -v <data path> --name <app>-data tianon/true
# Webapp container
docker run --volumes-from <app>-data --name <app> \
  -e VIRTUAL_HOST=<url> \
  <image> &

But nginx can't write into the data folder, and if I go in my container: 但是nginx无法写入数据文件夹,并且如果我进入容器:

drwxr-xr-x  2 root     root       4096 Dec 16 19:03 data
drwxr-xr-x  3 www-data www-data   4096 Dec 16 18:57 doc
drwxr-xr-x  2 www-data www-data   4096 Dec 16 18:57 images

I do a chown in my Dockerfile image, but it looks like --volumes-from changes that. 我在Dockerfile映像中做了一个chown,但是看起来--volumes-from改变了它。

What should I do to give the data folder www-data ownership? 我该怎么做才能赋予data文件夹www-data所有权?

In theory ( issue 2259 ): 从理论上讲( issue 2259 ):

If you chown the volume (on the host side) before bind-mounting it, it will work. 如果chown绑定安装前的体积(在主机端),它会工作。

In that case, you could do: 在这种情况下,您可以执行以下操作:

mkdir /tmp/www
chown 101:101 /tmp/www
docker run -v /tmp/www:/var/www ubuntu stat -c "%U %G" /var/www

(Assuming that 101:101 is the UID:GID of the www-data user in your container.) (假设101:101是您容器中www-data用户的UID:GID 。)

Note that it is not what you are doing: you are mounting an host folder in a data volume container (a tianon/true image, which is quite empty, see its Dockerfile ), and then mounting that data volume container into a regular container. 请注意,这不是您要执行的操作:您正在将主机文件夹装入数据卷容器( tianon/true映像,该映像非常空, 请参阅其Dockerfile ),然后将该数据卷容器装入常规容器。

Still, that might work. 不过,这可能行得通。

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

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