Dockerfile review

  • Review current image layers and launch work, then evaluate cache, runtime packaging and process-lifecycle improvements.
Diagram phase
100%
Current: OS parent, separate runtime-copy carrierSelect / build / gateCopy / mount filesFROMFROMexecute carriercopy / modifymountselect appinit → JAR emptyDirmount filesThe application image and the runtime carrier each start from an Oracle Linux image. Both can share cached OS layers when their content digests match. OS PARENTOracle LinuxDirect and IL application images package the WAR before the configuration and scripts. The launcher runs under a non-root account. The runtime arrives separately at startup. APP IMAGEWAR + configlaunch scriptsA separate image carries Java, Tomcat and support files into Pod startup. Extracting archives in one layer and copying their contents in another retains both sets of bytes. RUNTIME IMAGEJDK + Tomcat+ support filesThe selected runtime carrier runs its setup launcher and copies files into this Pod runtime emptyDir. It also changes Tomcat configuration. Cached node image layers do not populate a fresh Pod volume.INIT EXECUTIONCopy runtimeThe application mounts the runtime prepared by the init container. The volume lasts for the Pod. A replacement Pod starts with an empty one.emptyDirRuntime filesTomcat stateApplication image executes its launcher against assembled runtime, JAR and external-artifact inputs. WAR expansion, JDBC/UCP relocation and configuration write remain startup work; existing WEB-INF can skip expansion within the same Pod.APP CONSUMERExpand / configurethen launchDependency init containers copy selected JARs into a volume mounted by the application. Direct receives packaged SMS/APIGW dependencies. IL selects its library inputs independently. OTHER IMAGESDirect / IL JARsSelected inputsSeparate existing artifacts/common mounts are not supplied by the runtime Docker parent. They remain release-compatibility inputs; current versioning/contents cannot be inferred from PVC names.EXISTING PVCSArtifactsCommon inputsFROMFROMexecute carriercopy / modifymountselect appinit → JAR emptyDirmount files

Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.

  • The OS image supplies the parent layers for the application and runtime images.
  • Each replacement Pod copies Java and Tomcat into an emptyDir before the WAR starts.
  • Cached image layers can save a pull. The runtime copy still consumes time and local I/O.
Image layers and Pod startup

Image layers and Pod startup

Dockerfile / BuildKit

What each image delivers

  • The Direct and IL application images contain the WAR, settings and launch scripts.
  • A separate runtime image supplies Java and Tomcat. An init container copies them into each new Pod’s emptyDir.
  • Dependency images supply the selected libraries. Direct includes SMS/APIGW dependencies. External artifacts have separate mounts.
Application image inputs · simplified Dockerfiledockerfile
# Illustrative layout. Supply an approved OS image and the application files.
ARG OS_IMAGE
FROM ${OS_IMAGE}
COPY service.war /app/service.war
COPY settings/ /app/settings/
COPY launch.sh /app/launch.sh
# The chart mounts Java and Tomcat from the runtime volume at startup.
Runtime carrier · simplified Dockerfiledockerfile
# Illustrative carrier. The build context supplies a compatible runtime tree.
ARG OS_IMAGE
FROM ${OS_IMAGE}
COPY runtime/ /payload/runtime/
# A Pod init container selects this image and copies /payload/runtime.

Where startup spends time

  • Each new Pod copies its runtime and libraries. A warm image cache saves the download and the copy still runs.
  • The launcher expands the WAR and prepares JDBC libraries and Tomcat configuration. After a container restart, it can skip expansion when the application directory already exists.
  • A partial extraction can leave that directory behind. Validate the complete release before reusing the files.
Init copy and consumer mount · Pod fragmentyaml
# Pod spec fragment. The two image references are placeholders.
# The carrier image contains sh, cp and /payload/runtime.
volumes:
  - name: runtime
    emptyDir: {}
initContainers:
  - name: copy-runtime
    image: example.invalid/runtime-carrier:r1
    command: ["sh", "-ec", "cp -R /payload/runtime/. /work/"]
    volumeMounts:
      - {name: runtime, mountPath: /work}
containers:
  - name: application
    image: example.invalid/service:r1
    volumeMounts:
      - {name: runtime, mountPath: /runtime}
# Set volume permissions for the image users and preserve required file modes.
WAR expansion on startup · launcher fragmentbash
#!/bin/sh
# Illustrative expansion step. The application path is on a writable Pod volume.
set -eu
: "${APP_DIR:?set the application directory}"
if [ ! -d "$APP_DIR/WEB-INF" ]; then
  mkdir -p "$APP_DIR"
  (cd "$APP_DIR" && jar -xf /app/service.war)
fi
# A failed extraction can already have created WEB-INF.
# Verify release identity and completeness before reusing the tree.

Reduce rebuild work

Change Why it helps Cost or prerequisite
Copy a stable WAR before frequently edited settings Settings-only changes can reuse the WAR layer Check which inputs change independently.
Set ownership as files enter the image Avoid a recursive ownership pass after every payload change Keep the launcher executable and volumes writable by the application user.
Copy only the final runtime tree from a build stage Temporary archives and extraction trees stay out of the final image Preserve required tools, libraries, certificates and file modes.
Set file ownership during the builddockerfile
# syntax=docker/dockerfile:1
# Illustrative build. Supply a digest-pinned Linux image with user/group tools.
ARG OS_IMAGE
FROM ${OS_IMAGE}
RUN groupadd --system app && useradd --system -g app app
WORKDIR /app
# Keep the more stable WAR layer reusable when settings or scripts change.
COPY --chown=app:app service.war /app/service.war
COPY --chown=app:app settings/ /app/settings/
COPY --chown=app:app --chmod=0755 launch.sh /app/launch.sh
USER app
ENTRYPOINT ["/app/launch.sh"]
Publish a common runtime parentdockerfile
# syntax=docker/dockerfile:1
# Supply approved OS and runtime-carrier digests. The carrier provides both trees.
ARG RUNTIME_PAYLOAD_IMAGE
ARG OS_IMAGE
FROM ${RUNTIME_PAYLOAD_IMAGE} AS payload
FROM ${OS_IMAGE}
# The final OS must supply the shared libraries used by the copied binaries.
COPY --from=payload /payload/java/ /opt/java/
COPY --from=payload /payload/tomcat/ /opt/tomcat/
ENV JAVA_HOME=/opt/java CATALINA_HOME=/opt/tomcat
# Publish the parent by digest. The child supplies the runtime user and launcher.

Move WAR expansion into the build

  • Use the common runtime as the parent of the application image and add the expanded WAR in a release layer. A runtime patch now requires rebuilding and testing every dependent image.
  • Adjust the launcher and chart mounts together. A volume mounted over the baked runtime hides those files. Keep generated configuration, temp files and logs in writable Pod-local paths.
  • Compare cold pulls, warm Pod restarts, init copy, expansion and time to readiness. Pre-expansion can add image bytes and shift work into CI.
Expand the WAR in a build stagedockerfile
# syntax=docker/dockerfile:1
# Supply the runtime parent by digest. It provides Java, Tomcat and jar.
ARG RUNTIME_IMAGE
FROM ${RUNTIME_IMAGE} AS unpack
COPY service.war /tmp/service.war
WORKDIR /tmp/expanded
RUN "$JAVA_HOME/bin/jar" -xf /tmp/service.war && test -d WEB-INF

FROM ${RUNTIME_IMAGE}
COPY --from=unpack /tmp/expanded/ /opt/app/
COPY --chmod=0755 launch-prepared.sh /opt/bin/launch-prepared.sh
# The launcher must configure Tomcat to serve /opt/app, use writable Pod-local
# state under CATALINA_BASE and load the selected libraries and certificates.
ENV CATALINA_BASE=/local/tomcat
USER 10001:10001
ENTRYPOINT ["/opt/bin/launch-prepared.sh"]

Tie container exit to the application

  • The current launcher backgrounds Tomcat and the metrics exporter, then follows the application log. A JVM crash can leave the log reader running until the health policy intervenes.
  • After preparation, run Tomcat in the foreground. Give the exporter its own supervised lifecycle and test the revised stop hook, probes and request drain.
  • Verify JVM exit, exporter exit and termination during a request. Retain the previous image and mount configuration for rollback.
Start Tomcat after preparationbash
#!/bin/sh
# Final launcher step after configuration, JDBC and certificates are ready.
# Requires a supervised exporter and a chart with compatible drain and stop hooks.
set -eu
: "${CATALINA_HOME:?set Tomcat home}"
: "${CATALINA_BASE:?set the writable Tomcat base}"
test -x "$CATALINA_HOME/bin/catalina.sh"
test -d "$CATALINA_BASE/conf"
exec "$CATALINA_HOME/bin/catalina.sh" run