Skip to content

commandDevOps and clouddocker

Dockerize

Writes a Dockerfile and .dockerignore for your project with layer caching, a slim final image and a non-root user.

npx workspacetemplates add dockerize --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/dockerize.md15 lines · 1.3 KBFile
---
description: Writes a Dockerfile and .dockerignore for your project with layer caching, a slim final image and a non-root user.
argument-hint: "[service name or port, optional]"
---

Containerize this project. Notes from the user: $ARGUMENTS

1. Detect the runtime from the manifest and lockfile (package.json, pyproject.toml, go.mod, Cargo.toml, pom.xml). Read the start script and note the port the app listens on. If a Dockerfile already exists, stop and ask whether to replace it.
2. Pick a pinned slim base tag (for example node:22-slim, python:3.12-slim, or a distroless runtime). Never use `latest`.
3. Order layers for caching: copy only the manifest and lockfile, install dependencies, then copy the source. Use a multi-stage build when a compiler or dev dependencies are needed, and copy only the built output into the final stage.
4. Create a non-root user and switch to it with USER before CMD. Set EXPOSE, a HEALTHCHECK if the app has a health route, and an exec-form CMD.
5. Write .dockerignore: .git, node_modules, build output, .env files, logs and test fixtures.
6. Run `docker build -t dockerize-check .` and report the image size. Start it briefly and confirm the port answers.

Show both files and the size, then ask before writing them to disk. Never bake secrets into the image.

What it does

Most first Dockerfiles run as root, copy the whole repository and rebuild every dependency on each change. This command inspects the project, picks the right base image and writes a build that avoids those habits.

It uses a multi-stage layout when the language needs a compiler, drops privileges before the app starts and builds the image once to prove the result runs. Existing Docker files are never overwritten without your answer.

Example

you › /dockerize port 3000

agent › Detected Node 22 with pnpm. Wrote a two-stage Dockerfile on node:22-slim running as user app, plus .dockerignore (8 entries). Test build: 148 MB, port 3000 answered on /health. Write both files?

Questions

Will it replace a Dockerfile I already have?
No. It stops and asks first, so a hand-tuned file is safe until you agree.
Does it need Docker installed?
The test build does. Without Docker it still writes the files and says the build was not verified.
  • Debug Container

    Commanddocker

    Free
  • Deploy Checklist

    CommandDevOps and cloud

    Free
  • Document Env Vars

    CommandDevOps and cloud

    Free
  • Review Terraform Plan

    Commandterraform

    Free