Skip to content
Cursor Rules Generator
Library4 sections

Docker Cursor Rules Template

Generate production-ready Docker Cursor rules for Project Rules (.mdc), AGENTS.md, or legacy .cursorrules. This template encodes stack-specific conventions for projects using Docker. Container platform for packaging apps and dependencies into portable runtimes.

The Complete Docker Cursor Rules

The full rule set in all three formats Cursor understands — copy the one your project uses. Project Rules (.mdc) load per-file via globs, AGENTS.md is portable across AI tools, and .cursorrules is the legacy single-file format.

Replacing a legacy file? Read the guide to migrate .cursorrules to Cursor Project Rules (.mdc) before copying this template into your project.

.cursor/rules/docker-dockerfile.mdc
---
description: "Dockerfile Best Practices"
alwaysApply: false
---
- Use multi-stage builds to minimize image size.
- Use specific base image tags — avoid :latest.
- Use    spaces for indentation.
- Combine RUN commands with && to reduce layers.
- Use .dockerignore to exclude unnecessary files.
- Use COPY over ADD unless you need URL or archive extraction.
.cursor/rules/docker-compose.mdc
---
description: "Docker Compose"
alwaysApply: false
---
- Define services in docker-compose.yml with explicit dependencies.
- Use depends_on with healthcheck conditions for startup ordering.
- Use named volumes for persistent data.
- Use environment variables and .env files — never hardcode secrets.
- Use profiles for optional services.
- Pin service image versions — don't use :latest in compose files.
.cursor/rules/docker-security.mdc
---
description: "Security"
alwaysApply: false
---
- Never run containers as root — use USER directive.
- Use non-root base images when available (node:slim, python:slim).
- Scan images with docker scout or trivy before deployment.
- Use secrets management (Docker secrets, HashiCorp Vault) — not env vars.
- Use read-only root filesystem when possible (--read-only).
- Limit container capabilities with --cap-drop and --cap-add.
.cursor/rules/docker-optimization.mdc
---
description: "Image Optimization"
alwaysApply: false
---
- Use Alpine or slim base images for smaller attack surface.
- Leverage build cache: copy dependency files before source code.
- Use --no-cache-dir for pip, --production for npm.
- Clean up package manager caches in the same RUN layer.
- Use layer caching strategically — order COPY commands by change frequency.
- Set resource limits (--memory, --cpus) for predictable performance.

Customize These Rules

The generator below is preloaded with the Docker template. Adjust indentation, quotes, naming, add your own rules, then download — no need to start from scratch on the homepage.

What This Template Covers

Required guidance

  • - Dockerfile Best Practices
  • - Docker Compose
  • - Security
  • - Image Optimization

Default style

  • - Indentation: 2 spaces
  • - Quotes: double
  • - Semicolons: disabled
  • - Naming: camelCase

Frequently Asked Questions

What does the Docker Cursor rules template include?
It includes 4 rule sections covering dockerfile best practices, docker compose, security and other Docker development conventions.
Can I generate Docker Project Rules and AGENTS.md from the same template?
Yes. The generator can export the same stack-specific guidance as modern Project Rules (.mdc), AGENTS.md, or a legacy .cursorrules file.
Should I combine Docker with other Cursor rules templates?
Yes. You can combine Docker with related templates such as TypeScript, Tailwind CSS, Docker, or backend frameworks when your project uses multiple technologies.