Create containers with current/custom user and group. Ideal for development environments.
You can use this image to run your app with your current/custom user and group.
docker run --rm -i -t \
--name my-user-test \
-e HOST_USER_NAME=$USERNAME \
-e HOST_USER_ID=$UID \
-e HOST_GROUP_NAME=$(id -g -n $USERNAME || echo $USERNAME) \
-e HOST_GROUP_ID=$(id -g $USERNAME) \
reduardo7/docker-host-user \
echo "User: \$USERNAME"
You can use this image as a base image (FROM reduardo7/docker-host-user
) to run your app with your current/custom user and group.
FROM reduardo7/docker-host-user
ENV HOST_USER_NAME 'foo'
...
CMD /init-user.sh echo 'hola'
User name. You can use $USERNAME
to get current user name.
User ID. You can use $UID
to get current user ID.
User group name. You can use $(id -g -n $USERNAME)
to get current user group name.
User group ID. You can use $(id -g $USERNAME)
to get current user group ID.
Optional. Default value: /bin/bash
.
User shell.
Optional. Default value: ${HOST_USER_NAME}
.
User password.
Optional. Default value: /home/${HOST_USER_NAME}
.
User home path.
docker-compose.yml
example:
version: "2"
services:
app:
image: reduardo7/docker-host-user
environment:
# Required:
HOST_USER_NAME: "u${USERNAME}"
HOST_USER_ID: "3003"
HOST_GROUP_NAME: "g${USERNAME}"
HOST_GROUP_ID: "7007"
# Optional:
USER_SHELL: "/bin/bash" # Default: /bin/bash
USER_PASSWORD: "123456789" # Default: ${HOST_USER_NAME}
PATH_HOME: "/home/myuserhome" # Default: /home/${HOST_USER_NAME}