adding-docker: Generate Production-Grade Docker Configurations for Your Application

Preface

Containerizing an application is often the first step when preparing to deploy to a server or CI pipeline. When writing a Dockerfile by hand, it’s easy to miss items or deviate from production-ready practices—such as multi-stage builds, dependency caching, .dockerignore, and docker-compose—and every time you switch language stacks you have to consult documentation again. Below we introduce the Cursor community–curated Skill adding-docker: when users ask to “containerize” or “add Docker support,” it follows a fixed workflow to detect the runtime and generate a practical set of Docker-related files.

What Is This

adding-docker is a reusable SKILL.md instruction that teaches an Agent to generate a production-oriented Dockerfile, docker-compose, and .dockerignore for your application. The official description positions it as: Dockerize an application with a production-ready Dockerfile, docker-compose setup, and .dockerignore.

It is maintained in the resource directory of the awesome-cursor-skills repository, consistent with the Agent Skills mechanism described in Cursor’s docs: after placing SKILL.md in the specified directory, the Agent will automatically discover it and follow the steps when the scenario matches. This Skill is not tied to a specific cloud provider or orchestration platform; it produces generic Docker files that can be used with local docker / docker compose or your existing deployment pipeline.

Core Features

According to the official SKILL.md, enabling this Skill leads the Agent to do roughly the following:

  1. Identify the runtime: Inspect files such as package.json, requirements.txt, go.mod, Cargo.toml to determine the language and framework.
  2. Write a multi-stage Dockerfile: Prefer small base images like Alpine; adjust build output directories, start commands, and base images according to the detected framework (the docs use a Node.js multi-stage example, including deps / build / runner stages).
  3. Generate .dockerignore: Exclude node_modules, build artifacts, .git, .env*, docs, etc., to avoid baking irrelevant files into the image.
  4. Create docker-compose.yml as needed: When the app depends on databases, Redis, etc., define app and dependent services (the example includes PostgreSQL 16 Alpine, volumes, and depends_on).
  5. Optional npm scripts: e.g., docker:build, docker:run for convenient local one-command build and run.

The Notes in the documentation also enforce several production habits: prioritize Alpine images to reduce size; do not bake .env into the image—use env_file or runtime injection instead; in monorepos, exclude irrelevant sub-packages in .dockerignore; for production deployments, add a HEALTHCHECK instruction.

Installation and Activation

The general guidance in awesome-cursor-skills is to copy a ready-made SKILL.md into .cursor/skills/ (user level) or the corresponding location in your project directory, and the Agent will discover it automatically.

This Skill’s source file is located at:

https://github.com/spencerpauly/awesome-cursor-skills/tree/main/resources/adding-docker

The steps can be summarized as:

  1. Open the above directory and obtain the Skill’s SKILL.md (and any accompanying files in the same directory, if present).
  2. Create a new directory under your local Cursor’s .cursor/skills/ (e.g., adding-docker) and place SKILL.md inside.
  3. Alternatively, place it under .cursor/skills/ in the root of the current project to scope it to that project only.

The fetched materials do not separately list installation differences for Codex CLI or Claude Code; if you use other Agent environments that support SKILL.md, place the same file according to that environment’s Skills directory conventions. The trigger is as officially described: use this Skill when the user asks to dockerize, containerize, or add Docker support to an application.

Typical Usage

The following snippets come from the official SKILL.md to illustrate the forms the Agent might generate; actual paths and commands should be adjusted according to your project stack.

Multi-stage Dockerfile (Node.js example excerpt)

The official example starts from node:20-alpine, installs dependencies and builds in stages, then sets NODE_ENV=production, exposes the port, and runs npm start in the runner stage. You should adjust the output directory (e.g., .next) and CMD to match your framework.

FROM node:20-alpine AS base

FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

FROM base AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public
COPY --from=build /app/package.json ./
EXPOSE 3000
CMD ["npm", "start"]

.dockerignore example

Reduce context size and avoid sending sensitive or irrelevant files into the build:

node_modules
.next
.git
.env*
*.md

docker-compose.yml example with a database

The app reads environment variables via env_file: .env, and the database uses a named volume for persistence:

services:
  app:
    build: .
    ports:
      - "3000:3000"
    env_file: .env
    depends_on:
      - db
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Optional package.json scripts

{
  "docker:build": "docker build -t myapp .",
  "docker:run": "docker compose up"
}

In Cursor, you can directly state your intent, e.g., “Add Docker to this Next project, with postgres.” After loading this Skill, the Agent will detect the stack and generate or modify files according to the steps above; after generation, it’s still recommended to run docker build / docker compose up locally to verify.

Use Cases and Notes

Who It’s For

  • Teams or individuals who already have a runnable application that isn’t containerized and want to quickly obtain a multi-stage Dockerfile and ignore rules.
  • Scenarios where you need to spin up the app plus dependencies (e.g., databases) locally with one command, and want a docker-compose.yml structure consistent with the official examples for easy further customization.
  • Cursor Agent users who want to standardize the “containerization” workflow via Skills to reduce omissions from ad-hoc prompting each time.

Limitations and Notes

  • The Skill outputs templated best practices and does not replace your review of image security, secret management, resource limits, and orchestration platforms; the database passwords in the examples are placeholders and must be replaced in production.
  • The docs explicitly require: do not copy .env into the image; sensitive configuration should be injected via env_file or at runtime.
  • In monorepos, you should additionally exclude sibling packages in .dockerignore; the Skill mentions this in Notes, but specific paths still need to be confirmed manually based on your repository structure.
  • For production deployments, add a HEALTHCHECK instruction; the Skill suggests this in Notes, but whether it appears in the final Dockerfile depends on the Agent’s execution and your subsequent modifications.

Closing

adding-docker turns “detect runtime → multi-stage Dockerfile → .dockerignore → optional compose and scripts” into a repeatable process for an Agent, making it a good first-step scaffold for containerization. Official resource:

https://github.com/spencerpauly/awesome-cursor-skills/tree/main/resources/adding-docker

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye