Skip to content

Commit 3270d26

Browse files
committed
Add non-root user
Docker containers run as the `root` user by default. However, it is considered a best practice to run as a non-root user when possible. This commit will add a non-root user `apps` (UID `568`) and group `apps` (GID `568`) for this purpose. This commit will also add the `shadow` apk package to use the Docker-recommended `groupadd` and `useradd` commands. For the `docker run`, add the `-u`, `--user` option (`-u apps`). For Docker Compose, add the `user` key to the appropriate service (`user: apps`). - https://docs.docker.com/build/building/best-practices/#user - https://docs.docker.com/reference/cli/docker/container/run/ - https://docs.docker.com/reference/compose-file/services/#user - https://pkgs.alpinelinux.org/package/edge/community/x86_64/shadow
1 parent 373b560 commit 3270d26

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,38 @@ Supported [environment variables](https://docs.docker.com/reference/cli/docker/c
3838

3939
[Multi-platform builds](https://docs.docker.com/build/building/multi-platform/) are provided for the `linux/amd64` and `linux/arm64` platforms. If running on a different platform, use the [`--platform` option](https://docs.docker.com/reference/cli/docker/container/run/) to emulate a supported platform.
4040

41+
### Users
42+
43+
Docker containers run as the `root` user by default. However, it is [considered a best practice](https://docs.docker.com/build/building/best-practices/#user) to run as a non-root user when possible. The `dovi_tool` container image provides a non-root user `apps` (UID `568`) and group `apps` (GID `568`) for this purpose.
44+
45+
For the `docker run` CLI, add the [`-u`, `--user` option](https://docs.docker.com/reference/cli/docker/container/run/) (`-u apps`) to run as the non-root user.
46+
47+
```sh
48+
docker run --rm -it -u apps -v /path/to/media:/opt/media --entrypoint ash ghcr.io/br3ndonland/dovi_tool
49+
```
50+
51+
For Docker Compose, add the [`user` key](https://docs.docker.com/reference/compose-file/services/#user) to the appropriate service (`user: apps`) to run as the non-root user.
52+
53+
```yaml
54+
# compose.yaml
55+
name: dovi_tool
56+
services:
57+
dovi_tool:
58+
image: ghcr.io/br3ndonland/dovi_tool
59+
container_name: ${COMPOSE_PROJECT_NAME}
60+
pull_policy: always
61+
restart: "no"
62+
user: apps
63+
stdin_open: true
64+
tty: true
65+
entrypoint: ash
66+
environment:
67+
- STOP_IF_FEL=1
68+
- TZ=
69+
volumes:
70+
- /path/to/media:/opt/media
71+
```
72+
4173
## Notes
4274
4375
### Dolby Vision Enhancement Layers

dovi_tool/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LABEL org.opencontainers.image.source="https://github.com/br3ndonland/dovi_tool"
88
LABEL org.opencontainers.image.title="dovi_tool"
99
LABEL org.opencontainers.image.url="https://github.com/br3ndonland/dovi_tool/pkgs/container/dovi_tool"
1010

11-
RUN apk add --no-cache --upgrade jq mediainfo mkvtoolnix
11+
RUN apk add --no-cache --upgrade jq mediainfo mkvtoolnix shadow
1212
RUN <<HEREDOC
1313
set -e -o pipefail
1414
case $TARGETARCH in
@@ -24,6 +24,7 @@ tar -xvf /tmp/${DOVI_TOOL_ARCHIVE} -C /usr/local/bin
2424
tar -xvf /tmp/${HDR10PLUS_TOOL_ARCHIVE} -C /usr/local/bin
2525
rm -rf /tmp/*
2626
HEREDOC
27+
RUN groupadd -g 568 apps && useradd --no-log-init -r -u 568 -g apps apps
2728

2829
COPY --link ./dovi_tool_editor_config.json ./dovi_tool_generator_config.json /config/
2930
COPY --link --chmod=755 ./entrypoint.sh /usr/local/bin/entrypoint.sh

0 commit comments

Comments
 (0)