GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docker-build-tutorial/Dockerfile at main · Krishna-skk/java-docker-build-tutorial

Expand file tree

/

Dockerfile

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
62 lines (51 loc) · 1.89 KB
/

Dockerfile

Copy path

File metadata and controls

62 lines (51 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# syntax=docker/dockerfile:1
# We use a multi-stage build setup.
# (https://docs.docker.com/build/building/multi-stage/)
###############################################################################
# Stage 1 (to create a "build" image) #
###############################################################################
FROM eclipse-temurin:22-jdk-alpine AS builder
# Smoke test to verify if java is available.
RUN java -version
### Build a downsized JRE
# Required for jlink's `--strip-debug` option.
RUN apk add --no-cache binutils
RUN jlink \
--verbose \
--add-modules ALL-MODULE-PATH \
--compress=2 \
--no-header-files \
--no-man-pages \
--strip-debug \
--output /minimal-jre
# Build and package the app.
COPY . /usr/src/myapp/
WORKDIR /usr/src/myapp/
RUN ./mvnw package
###############################################################################
# Stage 2 (to create a downsized "container executable", ~131MB) #
###############################################################################
FROM alpine:latest
ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"
RUN apk --no-cache add ca-certificates
# Add app user.
ARG USER_NAME="appuser"
ARG USER_ID="1000"
ARG GROUP_NAME="apps"
ARG GROUP_ID="1000"
RUN addgroup --gid $GROUP_ID $GROUP_NAME && \
adduser --no-create-home --disabled-password --ingroup $GROUP_NAME --uid $USER_ID $USER_NAME
# Configure work directory.
ARG APP_DIR=/app
RUN mkdir $APP_DIR && \
chown -R $USER_NAME:$GROUP_NAME $APP_DIR
WORKDIR $APP_DIR
# Copy downsized JRE from builder image.
COPY --from=builder /minimal-jre $JAVA_HOME
# Copy packaged app from builder image.
COPY --from=builder --chown=$USER_NAME:$GROUP_NAME /usr/src/myapp/target/app.jar ./app.jar
# Run the application.
USER $USER_NAME:$GROUP_NAME
EXPOSE 8123
ENTRYPOINT ["java", "-XX:+UseZGC", "-XX:+ZGenerational", "-jar", "./app.jar"]
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.