BosskuAI Docker
Use this skill when the task involves Dockerizing an app, creating or reviewing Dockerfile, compose.yaml, .dockerignore, .env.example, service networks, volumes, local development sync, or "make this run with only Docker Compose".
How this differs from nearby skills
bosskuai-devops-iac: owns CI/CD, deployment flow, IaC, and operational platform risk. This skill owns concrete Dockerfile/Compose implementation.bosskuai-cybersecurity-risk: load alongside this skill when container config touches secrets, public ports, auth, PII, or production infrastructure.bosskuai-engineering-delivery: owns feature implementation and verification; this skill owns container runtime packaging and startup contract.bosskuai-performance-profiling: load when image build time, hot reload, filesystem sync, or runtime resource use is the main problem.bosskuai-vps-docker-deployment: puts these files on a server and keeps them running.
Non-negotiable Bossku Docker contract
- User startup must be one command: prefer Docker Compose V2,
docker compose up -d; support legacydocker-compose up -donly when the repo already uses it. - Put install/build/runtime setup in the
Dockerfile, not as longcommand:shell scripts in Compose. - Compose owns wiring: services, build args, ports,
env_file, volumes, networks, health checks, dependencies, and named volumes. - Do not hardcode credentials, tokens, private URLs, or passwords in
compose.yaml, Dockerfile, scripts, or committed.envfiles. - Use
.envorenv_filefor non-secret configuration; use Docker secrets or BuildKit secret mounts for real secrets. - Include
.env.examplewith placeholder values and commit that, not.env. - Keep the local workspace synced with the container for development using a bind mount such as
.:/app, with named volumes for dependency/cache directories that should not be overwritten. - Include explicit top-level
networks:and attach services intentionally, even though Compose creates a default network. - Include top-level
volumes:for persistent data such as databases, uploads, and dependency caches.
Workflow
Phase 1 - Read the app
- Identify stack, package manager, start command, build command, test command, ports, database/cache dependencies, and required env vars.
- Read existing Docker files before replacing them.
- Decide if the target is local development, production image, or both.
- Decide what must sync live from host to container and what must remain container-owned.
4a. Know the versions. Read the runtime version from the project's own files (manifest, lockfile,
.nvmrcor similar) and the base image tag from theFROMline. Check the latest stable image and its support end date live, on the image's official page, never from memory. 4b. Map the dependents. For each port, volume, network and env name the change touches, list its consumers (other Compose projects, CI, scripts) and how many replicas run. Done when each has a consumer or "none found".
Phase 2 - Dockerfile
- Use a specific base image suitable for the stack; avoid
latest. For production, pin the digest too (FROM <image>:<tag>@sha256:<digest>), read it withdocker buildx imagetools inspect <image>:<tag>, and re-pin on every update. - Set
WORKDIR. - Copy lockfiles before source to preserve dependency cache.
7a. Create
.dockerignorebefore anyCOPY . .: exclude.git,.env*, dependency and build directories, and local secrets. - Install dependencies inside the image.
- Copy source after dependencies.
- Build inside the image when the app has a build step.
- Run as a non-root user where practical.
- Expose the app port for documentation and tooling.
- Use
CMDorENTRYPOINTso Compose does not need a long shell command. - Use multi-stage builds when it reduces runtime image size or separates dev/build/prod concerns.
14a. Stop cleanly. Use the exec form of
CMDsodocker stopreaches the app, not/bin/sh. Addinit: trueif the app does not handle SIGTERM itself, since PID 1 drops signals it has no handler for.init: truedoes not fix shell form: tini signals only its direct child, and in shell form that child is/bin/sh. Setstop_grace_periodlonger than the longest request or job, or Docker kills the work in progress.
Phase 3 - Compose
- Use
compose.yamlor the repo's existing Compose filename convention. - Add app service
build:with context and Dockerfile. - Add
env_file: .envand keep YAML values as variable references, not literal secrets. - Add ports with variables where useful, for example
"${APP_PORT:-3000}:3000". - Add bind mounts for local source sync and named volumes for dependency folders or persistent data. On Linux a non-root container user cannot write host-owned files in a bind mount; match the UID or use a named volume.
- Add explicit service network names under top-level
networks:. - Add health checks for app and data services where a meaningful check exists.
- Use
depends_ononly for startup ordering; do not treat it as proof a service is ready unless health conditions are configured. - Keep the default user command simple: after files are present, the user should only need
docker compose up -d. 23a. Run schema migrations once, in amigrateservice that uses the same image as the app and waits for the database withdepends_on: db: condition: service_healthy. Each app service waits for it withdepends_on: migrate: condition: service_completed_successfully, sodocker compose up -druns the migrations first and the app starts only after they pass. Never run them in an entrypoint that every replica runs at start. Replicas that start together race on the same schema.
Phase 4 - Env and secrets
- Create/update
.env.examplewith safe placeholders. - Ensure
.envis ignored by git. - Use
env_filefor normal configuration. - Use Compose
secrets:for passwords, certificates, and API keys where supported by the app. - Use BuildKit
RUN --mount=type=secretfor build-time secrets; never useARGorENVfor build secrets.
Phase 5 - Verify
- Validate YAML and Dockerfile syntax.
- Run
docker compose configwhen Docker is available. - Run
docker compose up -d --buildfor first build if needed, then confirm normal startup works withdocker compose up -d. - Check
docker compose ps, logs, health checks, app URL, and volume sync. Walk the scenarios in the shared bar section 3 that reach the change (first start, repeatedup -d, restart afterstop, a dependency down); each is run or named untested. - Confirm no secrets appear in YAML, image layers, logs, git diff, or
.env.example. - For an app with a database, restore a copy of production data into a separate throwaway database container, never the live volume. Mask personal data (names, IDs, phone numbers, bank details) and keep the same column types and value formats. Run the migration there and compare row counts with production. Record the image digest you deploy. Prove the rollback by starting the previous digest of the app against that same migrated copy and checking health. A rollback changes the image, not the data, so back up the volume before a schema change. If you cannot get production data, ask the user for a masked copy or seed data; do not skip silently. For an app with no database, skip the data part and still record the digest and prove the rollback.
Starter Compose pattern
services:
app:
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
ports:
- "${APP_PORT:-3000}:3000"
volumes:
- .:/app
- app_node_modules:/app/node_modules
networks:
- app_network
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
env_file:
- .env
volumes:
- db_data:/var/lib/postgresql/data
networks:
- app_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"]
interval: 5s
retries: 10
volumes:
app_node_modules:
db_data:
networks:
app_network:
driver: bridge
Adapt this pattern to the stack. Do not copy Node-specific node_modules volumes into non-Node projects.
Postgres 18+ images declare the data volume at /var/lib/postgresql; 16 and 17 use /var/lib/postgresql/data. Moving 16/17 to 18 needs a dump/restore or pg_upgrade, not a tag bump.
Guardrails
- Do not put credentials directly in YAML, Dockerfile, shell scripts, or
.env.example. - Do not commit
.env; add it to.gitignorewhen missing. - Do not use bind mounts for production deployment unless that is explicitly required.
- Do not use a broad bind mount that hides installed container dependencies without adding named volumes for dependency directories.
- Do not leave privileged mode, host networking, Docker socket mounts, or root users enabled unless there is a documented reason.
- Do not make the user run manual install commands on the host after Dockerization.
- Do not let CRLF line endings reach shell entrypoints. On a Windows checkout, add
*.sh text eol=lfto.gitattributesand commit it. Git does not change shell scripts already on disk, so each script that still has CRLF must be checked out again. First rungit diff --ignore-cr-at-eol -- <script>. If it prints nothing, the only change is line endings andgit checkout -- <script>is safe. Thengit ls-files --eol <script>should showw/lf. Otherwise the container fails at start with "no such file or directory".
Output format
Docker summary:
Target: [dev / production / both]
Startup: docker compose up -d
Services: [app, db, cache, worker]
Env/secrets: [.env, .env.example, secrets]
Sync: [bind mounts / named volumes / compose watch]
Network: [network name]
Files changed:
[Dockerfile / compose.yaml / .dockerignore / .env.example / .gitignore]
Verification:
[docker compose config / build / up / logs / health / sync / secret scan]
References
../../references/checklists/docker-checklist.md../../references/checklists/devops-iac-checklist.md../../references/checklists/security-risk-checklist.md../../references/checklists/engineering-quality-bar.md
Hardening and isolation extras
- Compose hardening where the app allows it:
security_opt: [no-new-privileges:true],read_only: truewithtmpfsfor the paths it must write (/tmp, caches),cap_drop: [ALL]and add back only what is needed (for exampleNET_BIND_SERVICEbelow port 1024). Pin base images by version, or by digest for reproducibility. - Segment networks: put the database on a backend-only network reachable from the API, not the frontend. Publish data-service ports to
127.0.0.1for local use only and omitports:in production, where services talk over the Docker network by service name. - Keep dev-only settings (debug ports, verbose logging, bind mounts) in
compose.override.yamland production settings (restart policy, resource limits,target: production) in an explicit second file passed with-f. - One process per container; data in named volumes, because container storage is ephemeral. Compose alone is not production orchestration for multi-host workloads.
- A Linux container does not validate macOS or Windows behavior (shared Linux kernel; Windows containers need a Windows engine). Keep a native OS matrix in CI for path, quoting, shim and filesystem differences, and do not claim otherwise.
- Testing an installer or CLI that mutates files: mount the source read-only, copy it into a writable
tmpfsworkspace first, run as a non-root numeric UID, usenetwork_mode: noneby default, pass no host credentials, default to dry run, and call processes with argument arrays instead of interpolated shell strings. - Debugging: follow logs per service, open a shell in the service, check DNS from inside the app container (
nslookup db), and rebuild a single service without cache. Removing volumes with the down command's volume flag, or pruning unused images, deletes data; confirm that is intended first.
Adapted in part from ECC skills/docker-patterns (affaan-m/ECC, MIT).