Skip to content

Instantly share code, notes, and snippets.

@ferdinand-beyer
Created October 10, 2022 08:20
Show Gist options
  • Save ferdinand-beyer/1ea62d78d871c00da7e70d5a8c4c85d7 to your computer and use it in GitHub Desktop.
Save ferdinand-beyer/1ea62d78d871c00da7e70d5a8c4c85d7 to your computer and use it in GitHub Desktop.
Java Dockerfile template
#
# Following the best practices described here:
# https://snyk.io/blog/best-practices-to-build-java-containers-with-docker/
#
# Pinning the latest LTS (heree: '17-jre-alpine')
FROM eclipse-temurin:17.0.4.1_1-jre-alpine
RUN apk add dumb-init
RUN addgroup --system jvm && \
adduser -S -s /bin/false -G jvm jvm
RUN mkdir /app && \
chown -R jvm:jvm /app
WORKDIR /app
USER jvm
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
@ferdinand-beyer
Copy link
Author

For focal:

RUN apt-get update && \
    apt-get install -y \
        dumb-init \
        && \
    rm -rf /var/lib/apt/lists/*

RUN groupadd --system jvm && \
    useradd --system --shell /bin/false --gid jvm jvm
RUN mkdir /app && \
    chown -R jvm:jvm /app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment