Skip to content

Commit 55c2250

Browse files
Create docker-entrypoint.sh
1 parent 8377146 commit 55c2250

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docker-entrypoint.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# If running as root, check if we need to change UID/GID
5+
if [ "$(id -u)" = "0" ]; then
6+
# Check if USER_UID or USER_GID environment variables are set
7+
if [ -n "${USER_UID}" ] || [ -n "${USER_GID}" ]; then
8+
USER_UID=${USER_UID:-1000}
9+
USER_GID=${USER_GID:-1000}
10+
11+
# Modify user if UID/GID different from default
12+
if [ "${USER_UID}" != "1000" ] || [ "${USER_GID}" != "1000" ]; then
13+
echo "Adjusting user to UID=${USER_UID}, GID=${USER_GID}"
14+
15+
# Modify group if needed
16+
if [ "${USER_GID}" != "1000" ]; then
17+
groupmod -g ${USER_GID} appuser
18+
fi
19+
20+
# Modify user if needed
21+
if [ "${USER_UID}" != "1000" ]; then
22+
usermod -u ${USER_UID} appuser
23+
fi
24+
fi
25+
26+
# Fix ownership of app directory and data
27+
chown -R appuser:appuser /app
28+
29+
# Execute command as appuser
30+
exec gosu appuser "$@"
31+
fi
32+
fi
33+
34+
# Execute command directly if not running as root or no UID/GID specified
35+
exec "$@"

0 commit comments

Comments
 (0)