如何从 docker-compose.yml 更改 docker-compose.yml 中已安装卷的权限? [英] How can I change permission of mounted volumes in docker-compose.yml from the docker-compose.yml?

查看:45
本文介绍了如何从 docker-compose.yml 更改 docker-compose.yml 中已安装卷的权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

version: '2'
services:
    web:
        build:
            context: ./
            dockerfile: deploy/web.docker
        volumes:
            - ./:/var/www
        ports:
            - "8080:80"
        links:
            - app

如何在 docker-compose up -d --build 时自动更改权限 (chmod)/var/www?

How can I change permission (chmod) /var/www automatically when docker-compose up -d --build?

推荐答案

在容器中从主机绑定挂载目录时,文件和目录保持它们在主机上的权限.这是设计使然:当使用绑定挂载时,您允许容器访问来自主机的现有文件,而 Docker 不会对这些文件进行修改;这样做会非常危险(例如,绑定挂载您的主目录会更改主机主目录的文件权限,可能导致您的机器不再可用).

When bind-mounting a directory from the host in a container, files and directories maintain the permissions they have on the host. This is by design: when using a bind-mount, you're giving the container access to existing files from the host, and Docker won't make modifications to those files; doing so would be very dangerous (for example, bind-mounting your home-directory would change file permissions of your host's home directory, possibly leading to your machine no longer being usable).

要更改这些文件的权限,请更改它们在主机上的权限.

To change permissions of those files, change their permissions on the host.

您可以在我在 StackOverflow 上发布的另一个答案中找到更多相关信息:https://stackoverflow.com/a/29251160/1811501

You can find more information on this in another answer I posted on StackOverflow: https://stackoverflow.com/a/29251160/1811501

这篇关于如何从 docker-compose.yml 更改 docker-compose.yml 中已安装卷的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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