'Set User Permission for each volume within 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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Maze |
