Skip to content
Back to skills

Docker Containerization

ASecurity

Docker and container development — use when the user mentions Dockerfiles, multi-stage builds, Docker Compose, container optimization, image size reduction, DDEV, containerization, or dev environment setup with containers. NOT for CI/CD pipeline YAML or pipeline configuration (use cicd-pipelines), NOT for workflow orchestration or release automation (use workflow-automation), NOT for Kubernetes or container orchestration platforms (use cloud-native tooling).

  • 11 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 28, 2026
ai-agentstypescriptgophpshellbashsqlnodenodejsdockerkubernetes

Works with

  • cli
  • mcp

Security analysis

A100/100

Pro scans all 20 files and shows the line behind each finding

Scanned May 28, 2026

npx -y skills add viktorbezdek/skillstack --skill docker-containerization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docker Containerization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docker Containerization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/viktorbezdek-docker-containerization/badge)](https://www.skillsdirectory.com/skills/viktorbezdek-docker-containerization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: docker-containerization
description: Docker and container development — use when the user mentions Dockerfiles, multi-stage builds, Docker Compose, container optimization, image size reduction, DDEV, containerization, or dev environment setup with containers. NOT for CI/CD pipeline YAML or pipeline configuration (use cicd-pipelines), NOT for workflow orchestration or release automation (use workflow-automation), NOT for Kubernetes or container orchestration platforms (use cloud-native tooling).
license: MIT
---

# Docker Containerization Skill

Comprehensive guide for Docker containerization: Dockerfiles, multi-stage builds, Docker Compose orchestration, development environments, and advanced patterns.

## When to Use / Not Use

**Use when:**
- Writing or optimizing Dockerfiles (multi-stage builds, layer caching, image size)
- Setting up Docker Compose for multi-container apps (health checks, volumes, networks)
- Creating isolated development environments with worktrees
- Configuring DDEV for PHP/TYPO3 projects
- Managing ports, browser isolation, and CORS in multi-worktree setups
- Running container optimization analysis (`scripts/docker_optimize.py`)

**Do NOT use when:**
- CI/CD pipeline YAML or pipeline configuration -> use `cicd-pipelines`
- Workflow orchestration or release automation -> use `workflow-automation`
- Kubernetes or container orchestration platforms -> use cloud-native tooling
- Debugging containerized applications -> use `debugging` (but this skill helps with environment setup)

## Decision Tree

```
What Docker task do you need?
├── Write a Dockerfile
│   ├── Single-language app, no build step -> Single-stage FROM + COPY + CMD
│   ├── Compiled/bundled app (TypeScript, Go, wheel) -> Multi-stage build (build + production)
│   ├── Need smallest image -> Alpine or distroless base, multi-stage
│   └── PHP/TYPO3 project -> DDEV (see references/ddev-quickstart.md)
├── Set up Docker Compose
│   ├── Single app + DB -> 2 services, health check on DB, depends_on with condition
│   ├── Multiple services (app + DB + cache + worker) -> Named volumes, health checks, resource limits
│   ├── Need worktree isolation -> Port ranges per worktree, prefixed container names
│   └── Environment-specific configs -> Override files: docker-compose.override.yml
├── Optimize existing image
│   ├── Image too large -> Run docker_optimize.py, add .dockerignore, reorder layers
│   ├── Build too slow -> Reorder: COPY deps first, RUN install, then COPY source
│   └── Security issues -> Non-root user, specific version tags, no build tools in production
├── Development environment
│   ├── Git worktree isolation -> references/docker-worktree-strategy.md + worktree-manager.sh
│   ├── Browser isolation for E2E -> references/browser-isolation.md + setup-mcp-isolation.sh
│   └── Port conflicts -> references/port-allocation.md (systematic ranges)
└── Troubleshooting
    ├── Build fails -> Check Dockerfile syntax, cache, .dockerignore
    ├── Container can't connect -> Check network, service names, health checks
    ├── Data lost on restart -> Use named volumes (not anonymous/binds)
    └── DDEV issues -> references/ddev-troubleshooting.md
```

## Quick Start

### Basic Docker Workflow

```bash
# Create Dockerfile
cat > Dockerfile <<EOF
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
USER node
CMD ["node", "server.js"]
EOF

# Build and run
docker build -t myapp:1.0 .
docker run -d -p 3000:3000 --name myapp myapp:1.0
```

See: `references/docker-basics.md`

### Docker Compose Multi-Container App

```yaml
# docker-compose.yml
version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - DATABASE_URL=postgresql://user:***@db:5432/app

  db:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "user"]
      interval: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      retries: 5

volumes:
  postgres_data:
```

See: `references/docker-compose.md`

## Core Docker Concepts

### Dockerfile Best Practices

```dockerfile
# Use specific versions (not latest)
FROM node:20.11.0-alpine3.19

# Set working directory
WORKDIR /app

# Copy dependency files first (better caching)
COPY package*.json ./
RUN npm ci --only=production

# Copy application code
COPY . .

# Set environment variables
ENV NODE_ENV=production

# Document exposed ports
EXPOSE 3000

# Create and use non-root user (security)
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001
USER nodejs

# Default command
CMD ["node", "server.js"]
```

### Multi-Stage Builds

```dockerfile
# Stage 1: Build
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: Production (smaller image)
FROM node:20-alpine
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]
```

**Benefits:** Smaller images, improved security, no build tools in production.

### .dockerignore

```
node_modules
.git
.env
*.log
.DS_Store
README.md
docker-compose.yml
dist
coverage
```

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|---|---|---|
| Using `FROM:latest` tag | Non-reproducible builds; breakage when base image updates | Pin specific version: `node:20.11.0-alpine3.19` |
| Running as root in production | Security vulnerability; container escape risk | Create non-root user: `RUN adduser -S appuser` then `USER appuser` |
| Single-stage build for compiled apps | Build tools and dev deps in production image (1GB+ vs 200MB) | Multi-stage build: compile in build stage, copy artifacts to slim production stage |
| No .dockerignore | `node_modules`, `.git`, build artifacts copied into image, bloating size | Create .dockerignore excluding `node_modules`, `.git`, `dist`, `coverage`, `.env` |
| No health checks in Compose | Services start before dependencies ready; connection refused errors | Add `healthcheck` to each service, use `depends_on: condition: service_healthy` |
| Anonymous volumes for data | `docker compose down` removes data; data loss on cleanup | Use named volumes: `volumes: { postgres_data: }` and reference by name |
| COPY all files before RUN install | Any source change invalidates dependency cache; slow rebuilds | COPY `package*.json` first, RUN install, then COPY source (dependency layer caches) |
| No restart policy in production | Container stays down after crash or host reboot | Add `restart: unless-stopped` to production services |
| No resource limits | Runaway container starves host; OOM kills other services | Set `deploy.resources.limits.memory` and `cpus` per service |
| Missing `EXPOSE` documentation | Unclear which ports the container uses; conflicts | Document with `EXPOSE` even though it doesn't publish ports |
| Separate `RUN chown` after COPY | Creates extra layer; wastes image space | Use `COPY --chown=appuser:appgroup` in one step |

## Best Practices

### Dockerfiles
- Use specific image versions, not `latest`
- Run as non-root user
- Multi-stage builds to minimize size
- Implement health checks
- Set resource limits
- Keep images under 500MB
- Scan for vulnerabilities regularly

### Docker Compose
- Use named volumes for data persistence
- Implement health checks for all services
- Set restart policies for production
- Use environment-specific compose files
- Configure resource limits
- Enable logging with size limits
- Network isolation with custom networks

### Development Environments
- Use consistent port allocation across worktrees
- Isolate browser state for parallel testing
- Copy .env files when creating worktrees
- Configure CORS for worktree frontend ports
- Stop services when not in use

## Quick Reference

| Task | Command |
|------|---------|
| Build | `docker build -t myapp:1.0 .` |
| Run | `docker run -d -p 8080:3000 myapp:1.0` |
| Logs | `docker logs -f myapp` |
| Shell | `docker exec -it myapp /bin/sh` |
| Stop | `docker stop myapp` |
| Remove | `docker rm myapp` |
| Compose up | `docker compose up -d` |
| Compose down | `docker compose down` |
| Clean all | `docker system prune -a --volumes` |

## Scripts Reference

| Script | Purpose |
|--------|---------|
| `scripts/docker_optimize.py` | Analyze and optimize Dockerfiles |
| `scripts/validate-prerequisites.sh` | Check Docker, DDEV installation |
| `scripts/worktree-manager.sh` | Manage isolated worktree environments |
| `scripts/setup-mcp-isolation.sh` | Configure browser MCP isolation |
| `scripts/validate-worktree-connectivity.sh` | Test worktree service connectivity |
| `scripts/test-isolation.sh` | Test browser isolation |
| `scripts/migrate-browser-isolation.sh` | Migrate to new isolation config |

## Reference Navigation

| Topic | Reference File |
|-------|----------------|
| Docker basics and Dockerfile | `references/docker-basics.md` |
| Docker Compose orchestration | `references/docker-compose.md` |
| Extended patterns and examples | `references/extended-patterns.md` |
| Ghostmind meta.json config | `references/docker-meta-config.md` |
| Worktree Docker strategy | `references/docker-worktree-strategy.md` |
| Port allocation | `references/port-allocation.md` |
| Browser isolation | `references/browser-isolation.md` |
| CORS configuration | `references/cors-configuration.md` |
| Docker troubleshooting | `references/docker-troubleshooting.md` |
| DDEV quickstart | `references/ddev-quickstart.md` |
| DDEV advanced options | `references/ddev-advanced-options.md` |
| DDEV prerequisites | `references/ddev-prerequisites.md` |
| DDEV troubleshooting | `references/ddev-troubleshooting.md` |

## Resources

- **Docker Docs:** https://docs.docker.com
- **Docker Compose:** https://docs.docker.com/compose/
- **Dockerfile Reference:** https://docs.docker.com/engine/reference/builder/
- **DDEV:** https://ddev.readthedocs.io/
- **Docker Security:** https://docs.docker.com/engine/security/

## Integration

- **cicd-pipelines** -- Build and deploy Docker images this skill creates
- **workflow-automation** -- Automate deployment workflows using Docker containers
- **debugging** -- Debug containerized applications and CI/CD failures
- **testing-framework** -- Set up testing infrastructure inside containers

Files in this skill

  • SKILL.md10.5 KB
  • evals/evals.json1.3 KB
  • evals/trigger-evals.json2.2 KB
  • references/browser-isolation.md8.4 KB
  • references/cors-configuration.md5.8 KB
  • references/ddev-advanced-options.md8 KB
  • references/ddev-prerequisites.md5.6 KB
  • references/ddev-quickstart.md5.2 KB
  • references/ddev-troubleshooting.md3.8 KB
  • references/docker-basics.md5.7 KB
  • references/docker-compose.md4.7 KB
  • references/docker-meta-config.md5.7 KB
  • references/docker-troubleshooting.md10.8 KB
  • references/docker-worktree-strategy.md8.4 KB
  • references/extended-patterns.md6.8 KB
  • references/port-allocation.md3.6 KB
  • scripts/docker_optimize.py11.6 KB
  • scripts/migrate-browser-isolation.sh4 KB
  • scripts/setup-mcp-isolation.sh2.9 KB
  • scripts/test-isolation.sh4.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.