Dockerfiles
Encyclopedia home · Search machine-readable catalog
CF-001
Python fixture server
Copy to Dockerfile.
FROM python:3.12-slim
WORKDIR /app
COPY health.py .
USER 10001:10001
EXPOSE 8000
ENTRYPOINT ["python","health.py"]Verification. Use the health server below and build with docker build -t lab:web . Expect GET /healthz to pass.
Validation untested. Official reference
CF-002
FastAPI locked source build
Copy to Dockerfile.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --require-hashes -r requirements.txt
COPY app/ ./app/
USER 10001:10001
CMD ["uvicorn","app.main:app","--host","0.0.0.0","--port","8000"]Verification. Supply the generated hashes and deployed app. Verify startup and image user.
Validation untested. Official reference
CF-003
Go static binary build
Copy to Dockerfile.
FROM golang:1.24 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -mod=readonly -o /out/app ./cmd/app
FROM scratch
COPY --from=build /out/app /app
USER 10001:10001
ENTRYPOINT ["/app"]Verification. Build a static app. Include CA roots in runtime image when outbound TLS is required.
Validation untested. Official reference
CF-004
Build and serve a Node frontend
Copy to Dockerfile.
FROM node:22-bookworm-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:1.27-alpine
COPY --from=build /app/dist/ /usr/share/nginx/html/Verification. Use a lockfile and build script. Verify the app's actual output directory.
Validation untested. Official reference
CF-005
Run a JVM application
Copy to Dockerfile.
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --chown=10001:10001 target/app.jar ./app.jar
USER 10001:10001
ENTRYPOINT ["java","-XX:MaxRAMPercentage=75","-jar","app.jar"]Verification. Build target/app.jar before the image and verify memory in a constrained job.
Validation untested. Official reference
CF-006
Build and runtime targets
Copy to Dockerfile.
FROM python:3.12-slim AS base
WORKDIR /app
COPY . .
FROM base AS test
RUN python -m unittest discover -s tests
FROM base AS runtime
USER 10001:10001
CMD ["python","health.py"]Verification. Run docker build --target test explicitly. Building runtime does not automatically exercise test.
Validation untested. Official reference
CF-007
BuildKit download cache
Copy to Dockerfile.
# syntax=docker/dockerfile:1
FROM node:22-bookworm-slim
WORKDIR /app
COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev
COPY server.js .
USER node
CMD ["node","server.js"]Verification. Use BuildKit and test with cold and warm cache. The package lock remains authoritative.
Validation untested. Official reference
CF-008
Healthcheck without curl
Copy to Dockerfile.
FROM python:3.12-slim
COPY health.py /health.py
USER 10001:10001
HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["python","-c","from urllib.request import urlopen; urlopen('http://127.0.0.1:8000/healthz',timeout=2).read()"]
CMD ["python","/health.py"]Verification. Inspect .State.Health.Status and assert healthy before testing.
Validation untested. Official reference
CF-009
Expose a CLI entrypoint
Copy to Dockerfile.
FROM python:3.12-slim
COPY cli.py /cli.py
USER 10001:10001
ENTRYPOINT ["python","/cli.py"]
CMD ["--help"]Verification. Test default and explicit arguments. Avoid shell-form entrypoints if signals matter.
Validation untested. Official reference
CF-010
OCI labels from build inputs
Copy to Dockerfile.
FROM python:3.12-slim
ARG SOURCE_REVISION
LABEL org.opencontainers.image.revision=${SOURCE_REVISION}
COPY health.py /health.py
USER 10001:10001
ENTRYPOINT ["python","/health.py"]Verification. Supply git SHA with --build-arg and inspect the resulting image label.
Validation untested. Official reference