-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make Docker image run without root user (#67)
- Loading branch information
1 parent
e784093
commit 46eef1f
Showing
4 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
echo "Creating user and group..." | ||
|
||
PUID=${PUID:-1000} | ||
PGID=${PGID:-1000} | ||
|
||
# Check if the group with PGID exists; if not, create it | ||
if ! getent group pocket-id-group > /dev/null 2>&1; then | ||
addgroup -g "$PGID" pocket-id-group | ||
fi | ||
|
||
# Check if a user with PUID exists; if not, create it | ||
if ! id -u pocket-id > /dev/null 2>&1; then | ||
if ! getent passwd "$PUID" > /dev/null 2>&1; then | ||
adduser -u "$PUID" -G pocket-id-group pocket-id | ||
else | ||
# If a user with the PUID already exists, use that user | ||
existing_user=$(getent passwd "$PUID" | cut -d: -f1) | ||
echo "Using existing user: $existing_user" | ||
fi | ||
fi | ||
|
||
# Change ownership of the /app directory | ||
mkdir -p /app/backend/data | ||
find /app/backend/data \( ! -group "${PGID}" -o ! -user "${PUID}" \) -exec chown "${PUID}:${PGID}" {} + | ||
|
||
# Switch to the non-root user | ||
exec su-exec "$PUID:$PGID" "$@" |
File renamed without changes.