onepub
(Onepub)
January 14, 2024, 5:08am
1
I’m using the default mysql docker container that is published on dockerhub.
https://hub.docker.com/_/mysql
I’m using docker-compose to launch the container.
When it starts is uses uid 999 and gid 999.
I want to change the uid and gid along with the username and group to
user: mysql:2002
group: mysql:2002
I can get it to change the uid and gid by passing in the --user switch but can’t see a method of associating the correct user and group.
I’m hoping not to modify the standard mysql dockerfile as I then I have to maintain the updates.
So is there some where I can do this via docker-compose or similar?
rimelek
(Ákos Takács)
January 14, 2024, 5:42pm
2
Iű don’t understand the question.
If you can set the user id and the group id, that’s it. A user is just an ID and a config file that basically sets a label on that ID as username.
Where is this from? .
onepub
(Onepub)
January 14, 2024, 9:09pm
3
rimelek:
Where is this from? .
This is just show what I want to achieve.
The problem with using just IDs is that the container is creating files/directories and then setting their owner to ‘mysql’ which has an id of 999. So some of the files are not accessible.
This why I wanted to be able to control the name and uid.
onepub
(Onepub)
January 14, 2024, 9:34pm
4
I’ve raised an issue on the mysql container as this feels like a bug:
opened 09:32PM - 14 Jan 24 UTC
The doco on the official docker image states:
> Running as an arbitrary user
…
> If you know the permissions of your directory are already set appropriately (such as running against an existing database, as described above) or you have need of running mysqld with a specific UID/GID, it is possible to invoke this image with --user set to any value (other than root/0) in order to achieve the desired access/configuration:
However this doesn't appear to work.
When I pass --user 2002:2002 and start the container with an empty hosted mounted volume and then access
the innodb-data directory (from within the container) I see:
```
drwxrwx--- 6 2002 2002 4096 Jan 14 15:58 .
drwxr-xr-x 1 root root 4096 Jan 14 15:58 ..
-rwxrwx--- 1 mysql mysql 131 Jan 14 13:30 .my-healthcheck.cnf
-rwxrwx--- 1 mysql mysql 16883712 Jan 14 15:58 aria_log.00000001
-rwxrwx--- 1 mysql mysql 52 Jan 14 15:58 aria_log_control
-rwxrwx--- 1 2002 2002 9 Jan 14 15:58 ddl_recovery.log
-rwxrwx--- 1 2002 2002 828 Jan 14 15:58 ib_buffer_pool
-rwxrwx--- 1 mysql mysql 12582912 Jan 14 13:30 ibdata1
-rwxrwx--- 1 2002 2002 12582912 Jan 14 15:58 ibtmp1
-rwxrwx--- 1 mysql mysql 0 Jan 14 13:30 multi-master.info
drwxrwx--- 2 mysql mysql 4096 Jan 14 13:30 mysql
-rwxrwx--- 1 mysql mysql 15 Jan 14 13:30 mysql_upgrade_info
drwxrwx--- 2 mysql mysql 4096 Jan 14 13:30 op
drwxrwx--- 2 mysql mysql 4096 Jan 14 13:30 performance_schema
drwxrwx--- 2 mysql mysql 12288 Jan 14 13:30 sys
```
So whilst some of the files have the correct permission (2002) many of the files are still owned by the 'mysql' user/group rather than the expected 2002.
The only way to start the container is to chmod 777 on the host volumes.
If I set chmod to the more appropriate 770 then the container fails to start with:
2024-01-15 8:28:29 0 [ERROR] mariadbd: File '/innodb-data/aria_log_control' not found (Errcode: 13 "Permission denied")
As you can see the aria_log_control file is one of the files owned by mysql.
For completeness, here is the docker-compose file that I'm starting the container with:
```
mysql:
container_name: mysql
image: mariadb:10.11
restart: on-failure
environment:
# override from env file to be empty, otherwise it prevents proper initialization of mysql
MYSQL_ROOT_PASSWORD: ${MYSQL_ADMIN_PASSWORD}
MYSQL_DATABASE: ${MYSQL_SCHEMA}
MARIADB_AUTO_UPGRADE: "true"
command: >
--lower-case-table-names=1 --bind-address=127.0.0.1 --datadir=/innodb-data/ --innodb_log_group_home_dir=/innodb-logs/ --max-allowed-packet=512M --innodb_buffer_pool_chunk_size=${MYSQL_INNODB_BUFFER_POOL_CHUNK_SIZE-8M} --innodb_buffer_pool_size=${MYSQL_INNODB_BUFFER_POOL_SIZE-512M} --table_open_cache=${MYSQL_TABLE_OPEN_CACHE-512} --max_connections=${MYSQL_MAX_CONNECTIONS-98} --innodb_flush_neighbors=0 --innodb_fast_shutdown=1 --innodb_flush_log_at_trx_commit=1 --innodb_flush_method=fsync --innodb_doublewrite=0 --innodb_use_native_aio=0 --innodb_read_io_threads=10 --innodb_write_io_threads=10 --slow_query_log_file=/tmp/mysql-slow.log --long-query-time=0.3 --slow_query_log --innodb-print-all-deadlocks
# mem_limit: ${MYSQL_MEMORY}
volumes:
- /db/mysql-innodb-data:/innodb-data
- /db/mysql-innodb-logs:/innodb-logs
network_mode: "host"
logging:
driver: "journald"
user: 2002:2002
```
rimelek
(Ákos Takács)
January 14, 2024, 11:15pm
5
You shared a compose file in the issue using the mariadb image. That was indeed forked from MySQL, but it is not MySQL This is the mariadb image: https://hub.docker.com/_/mariadb , not what you linked in your first post.
onepub
(Onepub)
January 15, 2024, 9:40pm
6
oops, sorry. I inherited the project and assumed…