S

Smart Setup Docker Containers

Enterprise-grade command for setup, docker, containerization, multi. Includes structured workflows, validation checks, and reusable patterns for setup.

CommandClipticssetupv1.0.0MIT
0 views0 copies

Smart Setup Docker Containers

Create production-optimized Docker configurations with multi-stage builds, development workflows, Docker Compose orchestration, and security hardening for your detected application stack.

When to Use This Command

Run this command when...

  • You need a Dockerfile with multi-stage builds, layer optimization, and security best practices for your application
  • You want a Docker Compose setup that orchestrates your application with databases, caches, and message queues
  • You need separate development and production Docker configurations with hot reloading for dev
  • You want container security hardening including non-root users, minimal base images, and vulnerability scanning
  • You need CI/CD integration for building, tagging, and pushing images to a container registry

Quick Start

# .claude/commands/smart-setup-docker-containers.yaml name: Smart Setup Docker Containers description: Setup optimized Docker containerization with Compose inputs: - name: environment description: "dev, production, or both" default: "both"
# Setup for both development and production claude "smart-setup-docker-containers" # Setup development environment only claude "smart-setup-docker-containers --environment dev" # Setup with specific services claude "smart-setup-docker-containers --services postgres,redis"
Output:
  [detect] Application: Node.js 20 + TypeScript
  [create] Dockerfile (multi-stage: deps, build, runtime)
  [create] Dockerfile.dev (with hot reload)
  [create] docker-compose.yml (app + postgres + redis)
  [create] docker-compose.dev.yml (dev overrides)
  [create] .dockerignore
  [optimize] Final image: 145MB (from 1.2GB base)
  [security] Non-root user, no secrets in layers
  Done. 5 files created. Run: docker compose up

Core Concepts

ConceptDescription
Multi-Stage BuildsSeparate build and runtime stages to minimize final image size by excluding build tools and source
Development WorkflowDev containers with volume mounts for hot reloading, debugger attachment, and live code changes
Service OrchestrationDocker Compose configuration with application, database, cache, and supporting services
Security HardeningNon-root USER directive, minimal base images (alpine/distroless), and no secrets baked into layers
Layer OptimizationStrategic COPY ordering and dependency caching to maximize Docker layer cache hits
Docker Architecture:
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚         docker-compose.yml           β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚   App    β”‚ Database  β”‚    Cache      β”‚
  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
  β”‚ β”‚Node  β”‚ β”‚ β”‚Postgresβ”‚ β”‚ β”‚   Redis   β”‚ β”‚
  β”‚ β”‚Multi β”‚ β”‚ β”‚  :5432 β”‚ β”‚ β”‚   :6379   β”‚ β”‚
  β”‚ β”‚Stage β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
  β”‚ β””β”€β”€β”€β”€β”€β”€β”˜ β”‚           β”‚               β”‚
  β”‚  :3000   β”‚  Volume   β”‚    Volume     β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Configuration

ParameterTypeDefaultDescription
environmentstring"both"Target: dev, production, or both
servicesstringauto-detectedAdditional services: postgres, redis, mongodb, rabbitmq (comma-separated)
base_imagestring"alpine"Base image type: alpine (small), debian (compatible), or distroless (minimal)
registrystring""Container registry URL for image tagging (e.g., ghcr.io/org)
portintegerauto-detectedApplication port to expose

Best Practices

  1. Use multi-stage builds always -- Even simple applications benefit from separating build and runtime stages. A Node.js app drops from 1+ GB to under 200MB with proper staging.
  2. Order COPY commands strategically -- Copy package.json and lock files before source code. This lets Docker cache the dependency installation layer when only source code changes.
  3. Never run as root -- Add a USER node or USER appuser directive in your Dockerfile. Running as root inside containers is a security risk that most vulnerability scanners flag.
  4. Use .dockerignore aggressively -- Exclude node_modules, .git, test files, and documentation from the build context. This speeds up builds and reduces image size.
  5. Pin base image versions -- Use node:20.11-alpine instead of node:latest. Unpinned tags can introduce breaking changes or vulnerabilities when the base image updates.

Common Issues

  1. Hot reload not working in dev -- Volume mounts must map your source directory into the container. Ensure docker-compose.dev.yml has the correct volume path and the file watcher is configured for container environments.
  2. Image too large -- Common causes: using non-alpine base images, including dev dependencies in the final stage, or copying unnecessary files. Review each COPY statement and the .dockerignore file.
  3. Port conflicts with local services -- Docker services may conflict with locally running databases or applications on the same ports. Change the host port mapping in docker-compose.yml (e.g., 5433:5432).
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates