为Docker-Compose中的每个卷设置用户权限
这是我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Docker 和 Compose 都没有任何选项可以更改卷或绑定安装目录中文件的所有权。
您将一个文件和一个目录装载到
mysql
容器中。它们都将拥有主机上的数字用户和组所有者。这些数字 ID 可能存在于容器的 /etc/passwd 文件中,也可能不存在,但这通常并不重要。 Docker 中无法更改文件所有权,除非您的容器以 root 身份运行并运行 chown(1) 作为其启动序列的一部分。如果这两个东西有不同的所有权,您可能需要在启动容器之前在主机上更改它。
实际上,根据您所显示的内容,只要
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
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.