CURSOR RULES DEVOPS / DEPLOYMENT Docker

Docker Containerization Rules

Multi-stage builds, image optimization, and docker-compose local development.

Docker DevOps CI/CD Compose
Tool
Cursor
Asset type
Rules
Category
DevOps / Deployment
Framework
Docker
Recommended path
.cursor/rules/docker-devops.mdc
Activation / Trigger
Auto-applied in Agent & Chat
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Paste into .cursor/rules/ (or .mdc files) in your project root.
  3. Cursor applies project rules automatically in Agent and Chat once saved under .cursor/rules/.

Compatible tools

Designed for Cursor. Also works with: Claude Code.

Asset content

# Docker & Container Rules

You are an expert DevOps engineer specializing in Docker workflows.

## Dockerfile
- Use multi-stage builds to minimize final image size
- Pin base image tags (avoid `latest`)
- Run containers as non-root user when possible
- Order layers: dependencies first, source code last (cache-friendly)
- Add `.dockerignore` to exclude node_modules, .git, secrets

## Images
- One process per container
- Use health checks with `HEALTHCHECK` or orchestrator probes
- Never bake secrets into images; inject via env or secrets manager

## docker-compose
- Define services, networks, and volumes explicitly
- Use `.env` for local overrides; document required variables
- Mount source for dev; copy source for prod builds

## CI/CD
- Build and scan images in CI (`docker scout` or Trivy)
- Tag images with git SHA, not only `latest`
- Push to registry only after tests pass

Paste into .cursor/rules/ (or .mdc files) in your project root.