

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# Docker & Containerization — Cursor Rules2# Comprehensive rules for Docker, Docker Compose, and container best practices34## Project Context5You are working on a project that uses Docker for containerization. Containers are used6for local development, CI/CD pipelines, and production deployment. The codebase includes7Dockerfiles for application services and docker-compose files for orchestrating8multi-container environments.910## Tech Stack11- Docker Engine 24+12- Docker Compose v213- Multi-stage builds14- Container registries (Docker Hub, GitHub Container Registry, ECR)15- Orchestration: Docker Compose (dev), Kubernetes or ECS (production)1617## Dockerfile Best Practices1819### Multi-Stage Build Pattern20```dockerfile21# Stage 1: Build22FROM node:20-alpine AS builder23WORKDIR /app2425# Install dependencies first (better cache utilization)26COPY package.json package-lock.json ./27RUN npm ci --production=false2829# Copy source and build30COPY . .31RUN npm run build3233# Stage 2: Production34FROM node:20-alpine AS production35WORKDIR /app3637# Create non-root user38RUN addgroup -S appgroup && adduser -S appuser -G appgroup3940# Copy only production dependencies and built artifacts41COPY --from=builder /app/package.json /app/package-lock.json ./42RUN npm ci --production && npm cache clean --force4344COPY --from=builder /app/dist ./dist4546# Switch to non-root user47USER appuser4849EXPOSE 300050HEALTHCHECK --interval=30s --timeout=3s --retries=3 \51 CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 15253CMD ["node", "dist/server.js"]54```5556### Python Multi-Stage57```dockerfile58FROM python:3.12-slim AS builder59WORKDIR /app6061RUN pip install --no-cache-dir uv62COPY pyproject.toml uv.lock ./63RUN uv sync --frozen --no-dev --no-editable6465COPY . .6667FROM python:3.12-slim AS production68WORKDIR /app6970RUN useradd --create-home --no-log-init appuser71COPY --from=builder /app/.venv .venv72COPY --from=builder /app/src ./src7374USER appuser75ENV PATH="/app/.venv/bin:$PATH"7677EXPOSE 800078HEALTHCHECK --interval=30s --timeout=3s --retries=3 \79 CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 18081CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]82```8384## Dockerfile Rules8586### Layer Ordering (Most to Least Frequently Changed)871. Base image882. System dependencies893. Create user904. Copy dependency manifests (package.json, requirements.txt)915. Install dependencies926. Copy source code937. Build step948. Runtime configuration (ENV, EXPOSE, HEALTHCHECK, CMD)9596### Image Size Optimization97- Use `-alpine` or `-slim` base images98- Use multi-stage builds to exclude build tools from production99- Combine `RUN` commands to reduce layers: `RUN apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*`100- Use `.dockerignore` to exclude unnecessary files101- Remove caches after installing packages: `npm cache clean --force`, `pip --no-cache-dir`102- Don't install dev dependencies in production: `npm ci --production`103104### .dockerignore105```106node_modules107.git108.env109.env.*110*.md111.vscode112.idea113coverage114.nyc_output115dist116__pycache__117*.pyc118.pytest_cache119.mypy_cache120docker-compose*.yml121Dockerfile*122```123124### Security125- Never run as root — create and switch to a non-root user126- Don't store secrets in the image (use environment variables or secrets manager)127- Pin base image versions: `node:20.11-alpine` not `node:latest`128- Scan images for vulnerabilities: `docker scout cves`129- Use `COPY` instead of `ADD` (ADD has extra behaviors: URL fetch, tar extraction)130- Don't install unnecessary packages (no `vim`, `curl` in production unless needed for healthcheck)131- Set read-only filesystem where possible: `--read-only`132133## Docker Compose134135### Development Setup136```yaml137# docker-compose.yml138services:139 app:140 build:141 context: .142 dockerfile: Dockerfile143 target: builder # Use build stage for development144 ports:145 - "3000:3000"146 volumes:147 - .:/app # Mount source for hot reload148 - /app/node_modules # Prevent overwriting container's node_modules149 environment:150 - NODE_ENV=development151 - DATABASE_URL=postgres://postgres:postgres@db:5432/appdb152 depends_on:153 db:154 condition: service_healthy155 command: npm run dev156157 db:158 image: postgres:16-alpine159 ports:160 - "5432:5432"161 environment:162 POSTGRES_USER: postgres163 POSTGRES_PASSWORD: postgres164 POSTGRES_DB: appdb165 volumes:166 - pgdata:/var/lib/postgresql/data167 healthcheck:168 test: ["CMD-SHELL", "pg_isready -U postgres"]169 interval: 5s170 timeout: 5s171 retries: 5172173 redis:174 image: redis:7-alpine175 ports:176 - "6379:6379"177 healthcheck:178 test: ["CMD", "redis-cli", "ping"]179 interval: 5s180 timeout: 5s181 retries: 5182183volumes:184 pgdata:185```186187### Compose Best Practices188- Use `depends_on` with `condition: service_healthy` for startup ordering189- Define healthchecks on all services190- Use named volumes for persistent data191- Use `.env` file for environment variables192- Override with `docker-compose.override.yml` for local customizations193- Use `profiles` for optional services (like monitoring tools)194195## Container Runtime196197### Environment Variables198- Use `ENV` in Dockerfile for build-time defaults199- Use `environment` in docker-compose for runtime configuration200- Use Docker secrets or external secret managers for sensitive values201- Never hardcode secrets in Dockerfiles or compose files202203### Networking204- Use Docker Compose service names as hostnames (`db`, `redis`)205- Only expose ports that need external access206- Use internal networks for service-to-service communication207- Define custom networks for service isolation208209### Health Checks210- Every service must have a health check211- Health checks should be lightweight and fast212- Test the actual service (HTTP endpoint, database ping), not just process existence213- Set reasonable intervals (10-30s) and retries (3-5)214215## Development Workflow216```bash217# Build and start all services218docker compose up --build219220# Run in background221docker compose up -d222223# View logs224docker compose logs -f app225226# Execute command in running container227docker compose exec app npm run test228229# Rebuild a single service230docker compose up --build app231232# Clean up everything233docker compose down -v --rmi local234```235236## Production Considerations237- Use specific image tags, never `latest`238- Set resource limits (memory, CPU)239- Use restart policies: `restart: unless-stopped`240- Log to stdout/stderr (Docker captures and forwards)241- Use read-only root filesystem with tmpfs for writable needs242- Implement graceful shutdown (handle SIGTERM)243- Use init process: `--init` flag or `tini`244245## Common Pitfalls246- Using `latest` tag in production (unpredictable builds)247- Running as root (security risk)248- Not using `.dockerignore` (large image, slow builds, secrets leaked)249- Installing dev dependencies in production images250- Not using multi-stage builds (bloated production images)251- Copying `node_modules` from host into container (platform mismatch)252- Not setting healthchecks (orchestrator can't detect unhealthy containers)253- Hardcoding configuration instead of using environment variables254- Not handling SIGTERM (container takes 10s to stop instead of shutting down gracefully)255- Storing state in the container filesystem (data lost on restart)256
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| survivorforge/cursor-rulesrules/ai-ml-python/.cursorrules · 16 | .cursorrules | teststylearchdeployment+2 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/langchain-ai/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+4 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/aws-serverless/.cursorrules · 16 | .cursorrules | teststylearchtypes+6 | 73/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/tailwindcss/.cursorrules · 16 | .cursorrules | lint-formatstylearchui+3 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/mern-stack/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-design-rest/.cursorrules · 16 | .cursorrules | lint-formatstylesecurityapi+3 | 69/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 92/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/chrome-extension/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+4 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/clean-code/.cursorrules · 16 | .cursorrules | styledo-notagent-behaviourdocs | 57/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/database-sql/.cursorrules · 16 | .cursorrules | styletypessecuritydatabase+3 | 65/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 16 | .cursorrules | buildteststylesecurity+3 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/django-rest/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/docker-devops/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 85/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/flutter-dart/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/fullstack-nextjs-prisma/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 96/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/go-gin/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+5 | 84/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/mobile-react-native/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 89/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-14-app-router/.cursorrules · 16 | .cursorrules | teststyletypestesting-strategy+3 | 71/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-app-router/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/nextjs-typescript/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 81/100 | 13 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| HerringtonDarkholme/megarepo.cursorrules · 17 | .cursorrules | setupbuildtestlint-format+13 | 96/100 | 14 days ago | |
| SkeneTechnologies/skene-cookbook.cursorrules · 51 | .cursorrules | setuptestlint-formatstyle+11 | 96/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 16 | .cursorrules | buildteststylesecurity+3 | 93/100 | 13 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 92/100 | 13 days ago | |
| fall-out-bug/sdp_lab.cursorrules · 0 | .cursorrules | setupbuildtestlint-format+3 | 86/100 | 14 days ago | |
| bashdeban/fastmind.cursorrules · 5 | .cursorrules | buildtestlint-formattypes+5 | 81/100 | 14 days ago | |
| storybookjs/storybook.cursorrules · 91k | .cursorrules | teststylearchdo-not+1 | 78/100 | 14 days ago | |
| forem/forem.cursorrules · 23k | .cursorrules | teststyletypesdatabase+4 | 71/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/survivorforge-cursor-rules-rules-devops-docker-cursorrules)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.