Skip to content

Instantly share code, notes, and snippets.

@Magnuti
Last active December 3, 2025 13:07
Show Gist options
  • Select an option

  • Save Magnuti/6a788e02e5f6d3818bcdf6f78b875554 to your computer and use it in GitHub Desktop.

Select an option

Save Magnuti/6a788e02e5f6d3818bcdf6f78b875554 to your computer and use it in GitHub Desktop.
Dockerfile snippets

Dockerfile snippets

Non-root user on Alpine

FROM alpine:3.22

# Create non-root user
RUN addgroup -g 1000 nonrootgroup && \
    adduser -D -u 1000 -G nonrootgroup nonrootuser

WORKDIR /app

COPY --chown=nonrootuser:nonrootgroup ...

# Switch to non-root user
USER nonrootuser

Non-root user on Debian

# Create non-root system user with explicit UID/GID
RUN addgroup --system --gid 1001 nonrootgroup && \
    adduser --system --uid 1001 --ingroup nonrootgroup nonrootuser

WORKDIR /app

COPY --chown=nonrootuser:nonrootgroup ...

# Switch to non-root user
USER nonrootuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment