-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·30 lines (22 loc) · 864 Bytes
/
entrypoint.sh
File metadata and controls
executable file
·30 lines (22 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# Based on: Deni Bertović https://denibertovic.com/posts/handling-permissions-with-docker-volumes/
# Use the LOCAL_USER_ID that was passed in, or fallback to 9001
USER_ID="${LOCAL_USER_ID:-9001}"
# Get the username that is associated with the user id (if any)
USER_NAME="$(getent passwd | awk -F: '$3 == '"$USER_ID"' { print $1 }')"
# Does the user already exist?
if [ "$USER_NAME" == "" ]; then
# No, we need to create it.
USER_NAME=user
# Create the home folder if it doesn't already exist.
if [ ! -d "/home/user" ]; then
MAKE_HOME='-m'
fi
# Create the user.
useradd --shell /bin/bash -u "$USER_ID" $MAKE_HOME user
export HOME="/home/$USER_NAME"
# Ensure home is owned by user (Docker may have created it as root when mounting volumes)
chown "$USER_NAME" $HOME
fi
# Execute the command
gosu "$USER_NAME" "$@"