Docker Community Forums

Share and learn in the Docker community.

Change UID/GID on container start

(Briefbote) #1

I’m trying to create a simple start-mariadb command based on mariadb:10 from the hub. My commands I execute look like this:

#! /bin/bash

if [ ! -d ~/.mariadb ]; then
  mkdir ~/.mariadb


docker run --name mariadb -p 3306:3306 -v ~/.mariadb:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$MARIADB_PW -e MYSQL_USER=$mysql_user -e MYSQL_PASSWORD=$mysql_password  mariadb:10
docker rm mariadb

Data in ~/mariadb is written with UID/GID of the mysql user within the running container, thus as a normal user I can not remove the created files. My idea was to change the UID and GID of the mysql user to the same as the user currently logged in user ( provided using -e UID=$UID for example ). Therefore I created a new Dockerfile with a new entrypoint.

The lines are:

#! /bin/bash
usermod -u $UID mysql
groupmod -g $GID mysql


This does not seem to work unfortunately. How could I provide the user the ability to remove ~/.mariadb without giving him sudo rights?

UPDATE Thought it should be possible using the new user namespaces. I added --userns-remap to /etc/init.d/docker and added --uidmap="999:1000:1" to docker run but this did not work.

Kind regards,