为Docker-Compose中的每个卷设置用户权限

发布于 2025-01-19 00:58:32 字数 652 浏览 0 评论 0原文

这是我的docker-compose文件,我有两个已安装的卷,

version: '3'
services:

  mysql:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    container_name: mysql
    restart: unless-stopped
    ports:
      - 3306:3306
    user: ${USER_ID}:${GROUP_ID}
    volumes:
      - "./storage/etc/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf"
      - "./storage/var/log/mysql:/var/log/mysql"

  phpmyadmin:
    image: phpmyadmin:5.1.1
    container_name: phpmyadmin
    restart: always
    ports:
      - 8080:80

如果我应用此Docker-Compose,则每个卷都需要一个不同的用户和组所有者,所有这些卷都将具有相似的用户和组所有者

我希望每个卷都可以选择一个指定的用户所有者

This is my docker-compose file, and I have two mounted volumes, and each volume require a different user and group owner

version: '3'
services:

  mysql:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    container_name: mysql
    restart: unless-stopped
    ports:
      - 3306:3306
    user: ${USER_ID}:${GROUP_ID}
    volumes:
      - "./storage/etc/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf"
      - "./storage/var/log/mysql:/var/log/mysql"

  phpmyadmin:
    image: phpmyadmin:5.1.1
    container_name: phpmyadmin
    restart: always
    ports:
      - 8080:80

If I'm applying this docker-compose all these volumes will have similar user and group owners
I expect that there is an option to make for each volume a specified user owner

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2025-01-26 00:58:32

Docker 和 Compose 都没有任何选项可以更改卷或绑定安装目录中文件的所有权。

您将一个文件和一个目录装载到 mysql 容器中。它们都将拥有主机上的数字用户和组所有者。这些数字 ID 可能存在于容器的 /etc/passwd 文件中,也可能不存在,但这通常并不重要。 Docker 中无法更改文件所有权,除非您的容器以 root 身份运行并运行 chown(1) 作为其启动序列的一部分。

如果这两个东西有不同的所有权,您可能需要在启动容器之前在主机上更改它。

sudo chown -R "${USER_ID}" ./storage

实际上,根据您所显示的内容,只要 mysqld.cnf 文件可读并且容器以 $USER_ID 作为日志目录的所有者运行,容器可能会成功运行。

Neither Docker nor Compose has any option to change the ownership of files in volumes or bind-mounted directories.

You mount a file and a directory into the mysql container. These will both have the numeric user and group owner they have on the host. Those numeric IDs may or may not exist in the container's /etc/passwd file, but it usually doesn't matter. There is no way in Docker to change the file ownership, unless your container runs as root and runs chown(1) as part of its startup sequence.

If these two things have different ownership, you may need to change this on the host before you launch the container

sudo chown -R "${USER_ID}" ./storage

In practice, given what you show, so long as the mysqld.cnf file is readable and the container runs with $USER_ID as the owner of the log directory, the container will probably run successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文