-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathentrypoint.sh
More file actions
26 lines (20 loc) · 744 Bytes
/
entrypoint.sh
File metadata and controls
26 lines (20 loc) · 744 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
#!/bin/sh
# 1. Read UID and GID from Env Vars (default to 1000 if not set)
USER_ID=${PUID:-1000}
GROUP_ID=${PGID:-1000}
echo "Starting with UID: $USER_ID, GID: $GROUP_ID"
# 2. Create the group if it doesn't exist
if ! getent group appgroup > /dev/null 2>&1; then
groupadd -g "$GROUP_ID" appgroup
fi
# 3. Create the user if it doesn't exist
if ! id -u appuser > /dev/null 2>&1; then
useradd -u "$USER_ID" -g "$GROUP_ID" -m -s /bin/sh appuser
fi
# 4. Handle permissions
# We must ensure the non-root user owns the app and data directories
# 'DATA_PATH' is defined in your Dockerfile as /data
chown -R appuser:appgroup /app
chown -R appuser:appgroup "$DATA_PATH"
# drop root priveleges and execute main command
exec gosu appuser "$@"