Docker Image Packaging Standard
*Status:* authoritative · Source: the ft-docker-standards skill and the rules/deploy/docker.md rule · Applies to: container images of FT backend services
The standard for how FT backend service images are built and packaged. Developers and DevOps engineers read it.
This page is the readable form of the ft-docker-standards skill. If they differ, the skill wins. Report the difference.
The skill overrides any other Dockerfile convention.
It governs image packaging: base image and build stages, user and permissions, ENTRYPOINT and heap flags, .dockerignore and image-level verification.
It does not govern the code inside the image. Package structure, DTOs, logging, database access and business-logic security belong to the Java standard.
Legend: a rule in D2 · Mandatory rules is mandatory. A rule in D3 · Recommended is recommended. A rule that names a thing to avoid forbids it.
| Section | Topic |
|---|---|
the three target environments |
|
mandatory rules (1-7 and 9) and recommendations (8 and 10) |
|
reference Dockerfile and measured result |
|
|
|
gotchas and porting checklist |
|
|
|
one-screen check before review |
D1 · Why: three target environments, one image
Every FT service image must run unmodified on all three environments.
| Environment | What it means for the image |
|---|---|
OpenShift, |
The platform assigns an arbitrary UID at pod start. It ignores the |
Vanilla Kubernetes |
No SCC exists, so the pod spec sets a fixed |
docker-compose |
No orchestrator injects an identity. The |
One Dockerfile, with one set of permissions, must satisfy all three at once. Section D2 · Mandatory rules lists the incidents behind the rules, and D6 · Gotchas lists the gotchas.
D2 · Mandatory rules
Rules 1 to 7 and rule 9 are mandatory. Each rule has one reason. The incidents behind the reasons follow the table.
| # | Rule | Reason |
|---|---|---|
1 |
|
OpenShift assigns an arbitrary UID that has no entry in |
2 |
Working directories are owned |
Restricted-v2 always puts the runtime UID in group 0. Write access for the owner protects nothing, and write access for group 0 is what an arbitrary UID has. |
3 |
Multi-stage build. No JDK, Gradle, Maven, gcc, pip or poetry in the final layer. No build credentials in the final layer. Pass GitHub Packages credentials with BuildKit |
Build tooling at runtime widens the CVE (known vulnerability) surface, and a leftover |
4 |
|
A concrete |
5 |
No rolling repositories ( |
A rolling branch trades a pinned, tested package set for whatever the branch holds on the day of the rebuild. The fixes usually reach the stable branch within weeks. |
6 |
|
The JVM is then PID 1 with no shell in between. This is the right practice with one less moving part. It does not fix a signal-handling defect. |
7 |
Heap with |
A fixed |
9 |
Pin the base image by digest, not by a floating tag such as |
A rebuild months later does not pick up an unrelated base change. |
Incidents behind the rules
-
Rule 2. On
service-api, OpenShift ran the pod asuid=1000880000. The log-directory write succeeded only becausegid=0withg+rwX. -
Rule 4. The Dockerfile of
TR069_EmulatorusedCOPY ./. ./with no.dockerignore. The glob matched.git. The whole.gitdirectory was baked into every image, including a credential header persisted byactions/checkoutwith liveadmin:org, repo, write:packagesscopes. It was served from a running production pod. -
Rule 5.
ftacsandhazelcastappendeddl-cdn.alpinelinux.org/alpine/edge/mainto fix specific CVEs. -
Rule 6. The earlier
docker-entrypoint.shofservice-apiusedexec gosu, which already forwardedSIGTERM(measured exit in 8.2 s on the old image). Do not claim that exec form fixes a signal-handling defect. -
Rule 7. The
-Xmx1goftr069-emulatoris the example the rule forbids.
D3 · Recommended
Rules 8 and 10 are recommended. Rule 9 (the digest pin) is mandatory and sits in D2 · Mandatory rules.
| # | Recommendation and reason |
|---|---|
8 |
Alpine base where there are no native dependencies. |
10 |
No duplicated artifact in the image. |
D4 · Reference Dockerfile
The service-api repository (branch docker-optimisation) is the verified reference.
It is the first service that passed all three environments under this standard.
Copy this file as the starting point for any other service.
Section D7 · Porting checklist lists what must change for each service.
# syntax=docker/dockerfile:1.7
# FT reference Dockerfile. Standard: ft-ai-toolkit/skills/ft-docker-standards/SKILL.md
# Target environments: OpenShift (restricted-v2, arbitrary uid), vanilla k8s, docker-compose.
# --- build ---
FROM eclipse-temurin:25-jdk-alpine AS builder
WORKDIR /build
# Build description first: this layer is reused while dependencies are unchanged.
COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle ./
RUN chmod +x ./gradlew
# GitHub Packages credentials arrive via BuildKit secrets and never land in a layer.
RUN --mount=type=secret,id=github_user \
--mount=type=secret,id=github_token \
mkdir -p /root/.gradle && \
printf 'publish.username=%s\n' "$(cat /run/secrets/github_user)" > /root/.gradle/gradle.properties && \
printf 'publish.token=%s\n' "$(cat /run/secrets/github_token)" >> /root/.gradle/gradle.properties
COPY src src
RUN ./gradlew bootJar -x test --no-daemon
# --- runtime ---
FROM eclipse-temurin:25-jre-alpine
# Overriding ENTRYPOINT removes /__cacert_entrypoint.sh (custom-CA import).
# A service that needs a private CA mounts a truststore file and adds
# -Djavax.net.ssl.trustStore=/path -Djavax.net.ssl.trustStorePassword=...
# to JAVA_TOOL_OPTIONS.
# MaxRAMPercentage instead of -Xmx: the JVM must respect the container limit.
# A Helm or compose `env:` entry named JAVA_TOOL_OPTIONS REPLACES this value.
# Any override MUST include "-XX:+UseContainerSupport -XX:MaxRAMPercentage=60.0".
# A comment cannot sit inside a multi-line ENV: Docker does not parse it there.
ENV APP_HOME=/app \
SPRING_PROFILES_ACTIVE=mysql \
TZ=UTC \
JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=60.0"
WORKDIR ${APP_HOME}
# uid 1001 with primary group 0: permissions go to the group, not the owner.
# `apk upgrade` pulls fixes already published in the pinned STABLE branch.
# It adds no repository line. The trade-off is accepted: the build is not
# reproducible over time within the stable branch.
RUN apk upgrade --no-cache \
&& apk add --no-cache curl tzdata \
&& adduser -D -H -u 1001 -G root appuser \
&& mkdir -p ${APP_HOME}/logs \
&& chown -R 1001:0 ${APP_HOME} \
&& chmod -R g+rwX ${APP_HOME}
COPY --from=builder --chown=1001:0 /build/build/libs/service-api.jar ${APP_HOME}/app.jar
COPY --chown=1001:0 version.xml ${APP_HOME}/version.xml
USER 1001
EXPOSE 8080 8443
# docker-compose is a supported target, so the healthcheck branches on
# SERVER_SSL_ENABLED. Otherwise an SSL container reports permanently unhealthy.
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD if [ "$SERVER_SSL_ENABLED" = "true" ]; then \
curl -k -fsS "https://localhost:${HTTPS_PORT:-8443}/iot-webservice/actuator/health" || exit 1; \
else \
curl -fsS "http://localhost:${PORT:-8080}/iot-webservice/actuator/health" || exit 1; \
fi
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
LABEL org.opencontainers.image.description="Service API" \
org.opencontainers.image.source="https://github.com/Friendly-Technologies/service-api"
Pilot evidence (service-api)
| Metric | Before (1.0.1_0.0.1) |
After (1.0.1_0.0.4) |
|---|---|---|
Critical CVEs |
4 |
0 |
High CVEs |
37 |
13 |
Size |
304 MB |
169 MB |
Runs as |
root |
uid 1001, or an arbitrary uid with gid 0 |
The drop from 4 Critical CVEs to 0 needed one change outside the Dockerfile.
The Spring Boot plugin moved from 4.0.3 to 4.0.6 in build.gradle.
The build also pins tomcat-embed-core, -el and -websocket to 11.0.24 (see D6 · Gotchas).
Swapping Debian JRE for Alpine JRE cannot change application-level dependency CVEs.
Verified on OpenShift (acs, restricted-v2) under an arbitrary injected uid (1000880000, gid 0):
-
The pod rolled out healthy.
-
The write to
/app/logssucceeded. -
actuator/healthreturned200. -
MaxHeapSizewas1,289,748,480bytes against a 2Gi limit. That is 60.06% of the limit and matchesMaxRAMPercentage=60.0. The JVM default of 25% would have produced a smaller heap.
D5 · Verification
test-image.sh
The skill ft-docker-standards contains a script that checks an image (section test-image.sh).
Save it as test-image.sh and run bash test-image.sh <image>.
The script reads two optional variables: APP_DIR (default /app) and ARTIFACT (default $APP_DIR/app.jar).
Set them for a service with another layout, for example APP_DIR=/opt/FTACS ARTIFACT=/opt/FTACS/bin/start.sh bash test-image.sh <image>.
To prove a deployed pod after a rollout, use the skill ft-image-rollout-verification.
It prints ok or FAIL for each check and ends with PASS when nothing failed.
| Check | How |
|---|---|
The image declares |
|
The process runs as uid 1001 |
|
The primary group is 0 |
|
|
run with |
No JDK at runtime |
|
No Gradle at runtime |
run as |
No build credentials |
run as |
No |
run as |
The artifact is present |
|
|
|
The credential checks run as root on purpose.
/root is mode 0700 and owned by root.
As uid 1001 a check gets "permission denied", which reads as "not found" and prints a false ok.
The three environment checks
A pull request does not merge until all three checks pass for the changed image.
-
docker-compose: run the image against a named volume. A bind mount on macOS gives a false pass (see D6 · Gotchas). Confirm the process is non-root (
docker exec <c> idshowsuid=1001 gid=0). Confirm that a write into the volume succeeds. -
Vanilla Kubernetes: render the chart with
--set global.platform=kubernetes. Assert that the manifest carriesrunAsUser: 1001andrunAsNonRoot: true. Runkubectl apply --dry-run=clienton the output and confirm it succeeds. This is a render-time check, not a live-cluster check. It was verified withhelm templateandkubectl apply --dry-run=clientonly. Do not describe it as a live deployment check. -
OpenShift: deploy to the real cluster. With
oc exec, confirm thatidshows an arbitrary uid withgid=0. Confirm that a write to the working and log directory succeeds. Confirm that the health endpoint returns200. Confirm thatMaxHeapSize(fromjava -XX:+PrintFlagsFinal -version | grep -i maxheapsize) matches the intended percentage of the real memory limit and not the 25% default.
D6 · Gotchas
Each gotcha caused a real, verified incident during the service-api pilot.
| Gotcha | What to do |
|---|---|
|
|
Spring Boot 4.0.6 manages |
The fix line is 11.0.22. Raising the Spring Boot plugin version alone does not clear the Tomcat CVEs. |
|
The base image is built before some fixes land in the same stable branch ( |
A repository can hold a second Dockerfile that feeds live pipelines |
|
A Helm |
It does not append. Measured: the |
The credential check of |
As uid 1001 the check meets |
|
With no |
Overriding |
That script makes |
A |
No |
Create, |
That |
D7 · Porting checklist
Check every line below. Do not assume it when you copy D4 · Reference Dockerfile to another service.
| Item | What to verify |
|---|---|
|
The form is glob-free on purpose. It fails if the settings file is absent or named |
The build command |
Maven or Gradle. For Gradle, confirm that the |
The artifact path |
|
|
Confirm that the service has and needs this file. |
|
Set the correct default profile for the service. Do not copy |
The healthcheck context path |
|
|
Match the real listening ports. Do not default to |
BuildKit secret ids and the |
They must match what |
The Java version in the base image tag ( |
Match the JDK or JRE version the service requires. |
GitHub Packages dependencies |
A service that consumes them (for example an internal |
The companion rule: rules/deploy/docker.md
The toolkit also ships a short rule that loads when you edit a Dockerfile*, a .j2, .tpl or .tmpl template, a docker-compose*.yml or a .dockerignore.
See Rules for how paths: loading works.
The rule covers build and runtime practice around the image.
| Topic | Rule |
|---|---|
Two-file pattern |
|
Image hygiene |
No secrets in |
Spring Boot layers |
Layered JARs are mandatory in the multi-stage file. Enable |
JVM flags |
Set them through |
Timezone |
Decide |
Registry |
Push a semver tag and a git SHA tag. Enable tag immutability where the registry supports it. Deploy by digest. Scan on push and rescan on a schedule. A CRITICAL finding blocks. |
The rule follows the standard
The rule follows the standard, and on any conflict the standard wins:
Alpine where the service has no native dependency and the image test passes, a glibc base
otherwise; USER 1001 with writable directories owned 1001:0 and g+rwX;
MaxRAMPercentage=60.0, higher only with a measured off-heap headroom; and the base image pinned
by digest in every new or changed Dockerfile.
Review checklist
-
USER 1001is numeric. Working directories are1001:0withg+rwX. -
The base image is pinned by digest in a new or changed Dockerfile.
-
Multi-stage build. No build tooling and no credentials in the final layer. Secrets arrive through
--mount=type=secret. -
.dockerignoreexists.COPYlists concrete paths and has no.glob. -
No rolling repository.
apk upgrade --no-cacheonly inside the pinned stable branch. -
ENTRYPOINTis in exec form. -
JAVA_TOOL_OPTIONScarries-XX:+UseContainerSupport -XX:MaxRAMPercentage=60.0. No-Xmx. Chart and overlay overrides keep both flags. -
The directory is created, owned and chmodded in one
RUN, before theCOPYthat fills it. -
The healthcheck context path,
EXPOSE, profile and Java version match the service. -
test-image.shpasses. Compose, Kubernetes render and OpenShift checks are done, and the Kubernetes claim says "render-time only". -
The build dispatch passed
-f branch=<branch>, anddocker historyconfirms the content.