skills/containerfile-creator/SKILL.md
Create high-quality, secure, and performance-optimized Containerfiles (Dockerfiles) following best practices for multi-architecture builds, OpenShift/Kubernetes compatibility, and BuildKit cache optimization. Use when the user wants to: (1) create a new Containerfile or Dockerfile for any project (Python, Rust, Go, Node.js, .NET, or any language), (2) containerize an application with multi-stage builds, (3) optimize an existing Containerfile for security, performance, or image size, (4) review or improve container image build practices, (5) set up BuildKit cache mounts for package managers, (6) create OpenShift-compatible container images with non-root users and arbitrary UID support, (7) write a .dockerignore file, or (8) apply OCI LABEL standards.
npx skillsauth add jim60105/copilot-prompt containerfile-creatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create secure, efficient, and maintainable container images following open source best practices.
getenforce) if using Podman/BuildahContainerfile over Dockerfilealpine.Containerfile, distroless.Containerfile, ubi.ContainerfileEvery file MUST start with:
# syntax=docker/dockerfile:1
Only UID, VERSION, and RELEASE go at the top level:
# syntax=docker/dockerfile:1
ARG UID=1001
ARG VERSION=EDGE
ARG RELEASE=0
TARGETARCH and TARGETVARIANT MUST be declared inside each stage that uses them, not globally.
########################################
# Build stage
########################################
FROM python:3.13-alpine AS build
########################################
# Final stage
########################################
FROM python:3.13-alpine AS final
final# characters for stage separatorsbase stage when it requires non-trivial setup (e.g., installing system packages on UBI/Debian)Declare multi-arch variables inside each stage that uses cache mounts:
ARG TARGETARCH
ARG TARGETVARIANT
# Alpine APK
RUN --mount=type=cache,id=apk-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apk \
apk update && apk add -u package-name
# Debian/Ubuntu APT
RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \
--mount=type=cache,id=aptlists-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/lib/apt/lists \
apt-get update && apt-get install -y --no-install-recommends package-name
# Python PIP
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip \
pip install package-name
# Python UV
RUN --mount=type=cache,id=uv-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/uv \
uv pip install package-name
# DNF (Fedora/RHEL)
RUN --mount=type=cache,id=dnf-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/dnf \
dnf -y install package-name
# Alpine
ARG UID
RUN adduser -g "" -D $UID -u $UID -G root
# Debian/Ubuntu
ARG UID
RUN groupadd -g $UID $UID && \
useradd -l -u $UID -g $UID -m -s /bin/sh -N $UID
# Create directories
RUN install -d -m 775 -o $UID -g 0 /app && \
install -d -m 775 -o $UID -g 0 /licenses
# Copy files with proper ownership
COPY --link --chown=$UID:0 --chmod=775 source dest
COPY --link --chown=$UID:0 --chmod=775 LICENSE /licenses/Containerfile.LICENSE
COPY --link --chown=$UID:0 --chmod=775 project/LICENSE /licenses/project.LICENSE
By default, all code examples in this skill assume standard environments without SELinux or default Docker daemon execution. However, on SELinux-enforcing systems (such as Fedora, RHEL, CentOS) when using Podman or Buildah, --mount=type=bind instructions will fail with Permission denied (os error 13) because the container process cannot access host files without explicit SELinux security context relabeling.
getenforce outputs Enforcing).,relabel=shared (or ,relabel=private) is required on --mount=type=bind.relabel=shared) or standard Docker syntax is being used.Containerfile / Dockerfile:
# Note: relabel=shared is required for SELinux (Podman/Fedora/RHEL) rootless bind mounts
RUN --mount=type=cache,id=uv-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml,relabel=shared \
--mount=type=bind,source=uv.lock,target=uv.lock,relabel=shared \
uv sync --frozen --no-dev --no-install-project --no-editable
README.md or project documentation whenever podman build or podman compose build is a supported build workflow.Use dumb-init as PID 1 for proper signal handling. Download in a separate stage with SHA256 verification:
########################################
# Download stage
########################################
FROM docker.io/library/debian:bookworm-slim AS download
ARG TARGETARCH
ARG TARGETVARIANT
RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \
--mount=type=cache,id=aptlists-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/lib/apt/lists \
apt-get update && apt-get install -y --no-install-recommends curl ca-certificates
# Download dumb-init static binary (arch-aware) with SHA256 verification
RUN case "${TARGETARCH}" in \
amd64) DUMBINIT_ARCH="x86_64"; DUMBINIT_SHA256="e874b55f3279ca41415d290c512a7ba9d08f98041b28ae7c2acb19a545f1c4df" ;; \
arm64) DUMBINIT_ARCH="aarch64"; DUMBINIT_SHA256="b7d648f97154a99c539b63c55979cd29f005f88430fb383007fe3458340b795e" ;; \
*) echo "unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac && \
curl -fsSL "https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_${DUMBINIT_ARCH}" \
-o /dumb-init && \
echo "${DUMBINIT_SHA256} /dumb-init" | sha256sum -c -
Then copy in the final stage:
COPY --link --chown=$UID:0 --chmod=775 --from=download /dumb-init /usr/local/bin/dumb-init
When the application creates directories at runtime, use umask 0002 to preserve GID-0 group-write:
ENTRYPOINT ["dumb-init", "--"]
CMD ["sh", "-c", "umask 0002 && exec my-app"]
The exec replaces the shell so dumb-init's signal forwarding reaches the app directly.
Always use --link flag for COPY instructions to enable layer reuse across builds:
COPY --link --chown=$UID:0 --chmod=775 source dest
Do NOT use --link when destination path contains symlinks that need to be followed.
Follow this exact order in the final stage:
install -d)--link --chown=$UID:0 --chmod=775)LABEL MUST be the very last instruction. VERSION/RELEASE ARGs bust the cache for all subsequent instructions. Placing them last ensures maximum cache reuse.
ARG VERSION
ARG RELEASE
LABEL name="project-name" \
vendor="original-author" \
maintainer="user-id" \
url="https://github.com/user-id/project" \
version=${VERSION} \
release=${RELEASE} \
io.k8s.display-name="Display Name" \
summary="Brief summary" \
description="Detailed description with website reference"
HEALTHCHECK does not function in OCI/podman builds. Do NOT implement unless specifically requested.
When implementing:
COPY --link --from=ghcr.io/tarampampam/curl:8.7.1 /bin/curl /usr/local/bin/
HEALTHCHECK --interval=30s --timeout=2s --start-period=30s \
CMD [ "curl", "--fail", "http://localhost:8080/" ]
Run linting, type-checking, and tests inside the build. Use --mount=type=bind for test files to avoid caching them in layers:
########################################
# Test stage
########################################
FROM deps AS test
ARG TARGETARCH
ARG TARGETVARIANT
ENV PATH="/venv/bin${PATH:+:${PATH}}"
WORKDIR /app
# Install dev dependencies using separate cache to avoid conflicts
RUN --mount=type=cache,id=uv-test-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=/app/pyproject.toml \
--mount=type=bind,source=uv.lock,target=/app/uv.lock \
uv sync --frozen --no-install-project
COPY src/ src/
# Run quality checks and tests with bind-mounted test files
RUN --mount=type=bind,source=tests,target=/app/tests \
--mount=type=bind,source=pyproject.toml,target=/app/pyproject.toml \
pytest --junit-xml=/app/test-results.xml \
--cov=src \
--cov-report=xml:/app/coverage.xml \
--cov-fail-under=70 \
--verbose
Extract test reports from the build without running the full image:
########################################
# Report stage
# How to: podman build --target report --output type=local,dest=./out .
########################################
FROM scratch AS report
ARG UID=1001
COPY --chown=$UID:0 --chmod=775 --from=test /app/test-results.xml /
COPY --chown=$UID:0 --chmod=775 --from=test /app/coverage.xml /
Extract reports locally:
podman build --target report --output type=local,dest=./out .
Export statically linked binaries from the build:
########################################
# Binary stage
# How to: podman build --output=. --target=binary .
########################################
FROM scratch AS binary
COPY --from=builder /app/binary /
Binary stage is only for statically linked binaries or self-contained outputs.
Install large, rarely changed packages first, then project-specific dependencies:
RUN uv pip install torch==2.7.0 tensorflow>=2.16.1
RUN uv pip install -r requirements.txt
**/node_modules
**/*.log
**/.git
**/.gitignore
**/.env
**/.github
**/.vscode
**/bin
**/obj
**/dist
**/tmp
Load the appropriate reference file based on the project's language/pattern:
development
Generate images via the Stable Diffusion WebUI / Forge HTTP API (AUTOMATIC1111-compatible `/sdapi/v1/*`). Use when the user wants to (1) discover or pick a model / extra module (TE/VAE) / sampler / scheduler / style preset from a running sd-webui server, (2) generate an image with a given prompt (txt2img), (3) check generation progress, (4) cancel/interrupt an in-flight generation, (5) inspect or change a global sd-webui option (e.g. active checkpoint), or (6) test connectivity. This skill talks to a *generic* sd-webui-compatible server (AUTOMATIC1111, Forge, reForge, sd-webui-forge-classic). Do NOT trigger for requests that are purely writing the prompt itself.
testing
Verify implementation matches change artifacts. Use when the user wants to validate that implementation is complete, correct, and coherent before archiving.
development
Update an OpenSpec change by revising its existing planning artifacts and keeping them coherent with one another. Use when the user wants to revise a change's plan, fold new decisions into it, or reconcile its artifacts after an edit. Never edits code.
data-ai
Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.