Skip to content

Commit a413e34

Browse files
Update Dockerfile to use non-root user
This follows standard security best practices to NOT run applications inside docker containers as the root user if possible Signed-off-by: Matt Norton <matt@carrotmanmatt.com>
1 parent a133092 commit a413e34

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ WORKDIR /app
1111
RUN --mount=type=cache,target=/root/.cache/uv \
1212
--mount=type=bind,source=uv.lock,target=uv.lock \
1313
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
14-
uv sync --frozen --no-install-project --no-group dev
14+
uv sync --locked --no-install-project --no-group dev
1515

1616
COPY LICENSE /app/
1717
COPY config.py main.py messages.json /app/
@@ -22,13 +22,17 @@ COPY cogs/ /app/cogs/
2222

2323
FROM python:3.13-slim-trixie
2424

25+
RUN groupadd --system --gid 999 nonroot && useradd --system --gid 999 --uid 999 --create-home nonroot
26+
2527
LABEL org.opencontainers.image.source=https://github.com/CSSUoB/TeX-Bot-Py-V2
2628
LABEL org.opencontainers.image.licenses=Apache-2.0
2729

28-
COPY --from=builder --chown=app:app /app /app
30+
COPY --from=builder --chown=nonroot:nonroot /app /app
2931

3032
ENV LANG=C.UTF-8 PATH="/app/.venv/bin:$PATH"
3133

3234
WORKDIR /app
3335

36+
USER nonroot
37+
3438
ENTRYPOINT ["python", "-m", "main"]

0 commit comments

Comments
 (0)