Docker deploy

From WrongStack/WrongStack · View interactive version

Docker deploy is an AI agent skill from the GitHub repository WrongStack/WrongStack. Dockerfiles, docker compose and image builds: multi-stage, layer caching, size, non-root users, healthchecks, failing containers. Use this skill when writing or reviewing a Dockerfile, docker-compose setup, or container image build for a project, or when debugging a container that won't build, start

How to use this skill

Skill file

Docker Deploy

Selection card

Overview

A good image is small, reproducible, runs as a non-root user, and rebuilds

quickly because its layers are ordered by how often they change. Start from the

project as it is: the language and package manager (lockfile), the build

command, the start command, the port, and what the process needs at runtime

(environment, volumes, writable paths).

Rules

  1. Pre-flight: Inspect repo manifests & live base image registries first. Inspect package.json,

lockfiles, and existing Dockerfile / compose.yaml. Query Docker Hub or live container registries

to find current stable base image tags (e.g. node:26.13.0-bookworm-slim, postgres:18.6-alpine)

before configuring builds. Latest stable PostgreSQL is 18.6 (19 is beta),

checked 2026-11-02 against https://www.postgresql.org/support/versioning/.

  1. Multi-stage builds: build with the toolchain and dev dependencies, ship a

runtime stage with only production artifacts.

  1. Pin the base image to a specific version tag (optionally a digest); never

latest.

  1. Order layers for caching: copy dependency manifests and the lockfile,

install, then copy the source.

  1. Install from the lockfile (npm ci, pnpm install --frozen-lockfile,

pip install -r with hashes, go mod download).

  1. Run as a non-root user, and make only the paths the app writes to writable.
  2. No secrets in the image — no ARG/ENV for credentials, no copied .env.

Pass them at runtime, or use BuildKit secret mounts for build-time access.

  1. Use the exec form for ENTRYPOINT/CMD so signals reach the process, and

add an init (--init, or tini) when the app spawns children.

  1. Keep a .dockerignore that excludes .git, dependency folders, build output,

local env files, and tests.

  1. Add a HEALTHCHECK for long-running services, pointing at a cheap readiness

endpoint; one-shot jobs and CLIs don't need one.

Patterns

Node.js service with pnpm:

# syntax=docker/dockerfile:1
FROM node:26.13.0-bookworm-slim AS build
WORKDIR /app
RUN npm install --global pnpm@12.16.1
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build && pnpm prune --prod

FROM node:26.13.0-bookworm-slim AS runtime
ENV NODE_ENV=production
WORKDIR /app
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
COPY --from=build --chown=node:node /app/package.json ./
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
  CMD node -e "fetch('http://127.0.0.1:3000/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node", "dist/server.js"]

Build-time secret without baking it into a layer:

RUN --mount=type=secret,id=npmrc,target=/root/.npmrc pnpm install --frozen-lockfile
docker build --secret id=npmrc,src=$HOME/.npmrc -t app:$(git rev-parse --short HEAD) .

Compose for local development (the top-level version: key is obsolete):

services:
  app:
    build: .
    ports: ["3000:3000"]
    env_file: .env
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres:18.6
    environment:
      POSTGRES_PASSWORD: dev-only
    volumes: [db-data:/var/lib/postgresql]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      retries: 10
volumes:
  db-data:

Debugging a container

| Symptom | Check |

|---|---|

| Build cache never hits | Source copied before the dependency install; missing .dockerignore |

| Exits immediately | docker logs <id>; the CMD path relative to WORKDIR; missing build output in the runtime stage |

| Works locally, fails in the image | Missing runtime env var, native module built for a different libc (alpine vs glibc), dev dependency needed at runtime |

| Permission denied | Writing to a path owned by root while running as non-root |

| Ctrl+C or stop takes 10 s | Shell-form CMD swallowing signals; no init process |

| Unhealthy | Run the healthcheck command yourself inside the container |

Anti-patterns

Before returning

Reproducibility and deployment proof

For new Node targets, current stable is 26.13.0 (LTS 26.13.0) as checked 2026-11-02; verify

the official release schedule, available image tags and adapter support before

choosing a base. Corepack availability varies by Node release: provision the

declared package manager explicitly and pin its version. The example uses the checked stable target; verify tag availability

and pin the selected image digest before a production release.

For monorepos, include workspace manifests/config and required runtime assets;

single-package prune examples may break symlinks or workspace dependencies.

Build and run the final stage, check binding/readiness and stop behavior.

Record image digest; local startup and live redeployment are separate proofs.

Skills in scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.