boxboat / fixuid

Go binary to change Docker container user/group and file permissions at runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to send user:group as a command line parameter ?

dbjpanda opened this issue · comments

My entrypoint is something like below. So how can I pass the user:group value to fixuid instead from docker-compose.yml or docker run ? Why I want like this because I am trying to get the user id from a mounted file in entrypoint script.

HOST_CURRENT_USER_ID=$(stat -c "%u" /var/www/.gitkeep)
if [ $HOST_CURRENT_USER_ID -ne 0 ]; then
eval $( fixuid user:group) 
fi

Option 1:

Evaluate the mounted path outside the container in docker run:

docker run -u "${stat -c "%u" /path/to/.gitkeep}:${stat -c "%u" /path/to/.gitkeep}" --entrypoint "fixuid" <image>

Option 2:

Install sudo in your container and sudo in entrypoint

#!/bin/sh
# this is the entrypoint
echo "root    ALL=(ALL:ALL) ALL" >> /etc/sudoers
sudo -E -u "#$(stat -c '%u' /var/www/.gitkeep)" -g "#$(stat -c '%g' /var/www/.gitkeep)" fixuid "$@"