Add support for running Docker container as non-root user using docker-entrypoint.sh #1892
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT: Renamed
UID
andGID
toPUID
andPGID
, noticed that this was a convention used in another projects, and make sense since its "process" ID and process Group ID.This pull request introduces a new feature that allows running the
listmonk
Docker container as a non-root user by specifying thePUID
andPGID
through environment variables.This pull-request ensures backwards compatibility and super seeds pull-request #1891
Changes
Added a new script as the Docker entrypoint to handle user and group setup
docker-entrypoint.sh
with the added behavior:When the Docker image runs, it displays the PUID, PGID, USERNAME, and GROUP NAME that the Docker container is using.
Advantages
Usage
Docker
Kubernetes
Implementation notes
If user doesn't supply a
PGID
andPUID
thedocker-entrypoint.sh
assumes theroot
user keeping the legacy implementation working as expected.If the user specifies
PUID
andPGID
that don't exist inside the/etc/passwd/
and/etc/groups
thedocker-entrypoint.sh
creates the proper id's in this casePUID=1001
andPGID=1001
and assigned the user nameapp
and group nameapp
as default.If the user supplies
PUID
andPGID
that exist inside the/etc/passwd
and/etc/groups
thedocker-entrypoint.sh
respects the choose user id and groups and doesn't create them since they already exists but assume them.This is an
ls -la
of the docker container we we can see that the last step of the script is applying to the/listmonk
folder the appropriate user and permissions as specified by thePUID=22
andPGID=65534
:docker run -ti --rm -e PUID=22 -e PGID=65534 listmonk/listmonk Launching listmonk with user=[sshd] group=[nobody] uid=[22] gid=[65534] /listmonk $ ls -la total 17436 drwxr-xr-x 1 sshd nobody 4096 Jun 10 16:00 . drwxr-xr-x 1 root root 4096 Jun 10 16:27 .. -rw-r--r-- 1 sshd nobody 270 Jun 6 17:37 config-demo.toml -rw-r--r-- 1 sshd nobody 1029 Jun 6 17:37 config.toml -rwxr-xr-x 1 sshd nobody 17833192 Jun 10 16:00 listmonk