home / skills / shipshitdev / library / docker-expert

This skill helps you containerize NestJS and Next.js apps with optimized Dockerfiles and docker-compose patterns for development and production.

npx playbooks add skill shipshitdev/library --skill docker-expert

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.7 KB
---
name: docker-expert
description: Expert in Docker, docker-compose, Dockerfile patterns, and container orchestration for NestJS and Next.js applications. Use this skill when users need Docker setup, containerization, or docker-compose configuration.
---

# Docker Expert

## Overview

This skill enables AI assistants to help with Docker containerization, docker-compose setups, and container orchestration for micro startup infrastructure.

## When to Use This Skill

This skill activates when users need:

- Dockerfile creation for NestJS/Next.js
- docker-compose configuration
- Container networking and volumes
- Multi-stage builds optimization
- Health checks and restart policies
- MongoDB/Redis container setup

## Dockerfile Best Practices

### NestJS Multi-Stage Build

```dockerfile
FROM node:20-alpine AS base
WORKDIR /app

FROM base AS deps
COPY package*.json ./
RUN npm ci

FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM base AS runner
ENV NODE_ENV=production
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3001
CMD ["node", "dist/main.js"]
```

### Next.js Dockerfile

```dockerfile
FROM node:20-alpine AS base
WORKDIR /app

FROM base AS deps
COPY package*.json ./
RUN npm ci

FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM base AS runner
ENV NODE_ENV=production
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000
CMD ["npm", "start"]
```

## Docker Compose Patterns

### Development Setup

- Use volumes for live reload
- Mount source code
- Set restart: unless-stopped
- Configure networks

### Production Setup

- Use named volumes for persistence
- Set restart policies
- Configure health checks
- Use secrets management

### MongoDB with Docker Compose

```yaml
services:
  mongodb:
    image: mongo:7.0
    container_name: mongodb
    restart: unless-stopped
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
    volumes:
      - mongodb_data:/data/db
    networks:
      - app-network
    command: mongod --auth
```

## Health Checks

```yaml
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
  interval: 30s
  timeout: 10s
  retries: 3
  start_period: 40s
```

## Best Practices

- Use multi-stage builds to reduce image size
- Leverage layer caching
- Use .dockerignore
- Set appropriate restart policies
- Use health checks for containers
- Mount volumes for persistent data
- Use networks for service isolation

Overview

This skill helps build reliable Docker setups and docker-compose configurations for NestJS and Next.js applications. It focuses on multi-stage Dockerfile patterns, compose orchestration, health checks, volumes, and common database services. Use it to get production-ready container images and reproducible local development environments.

How this skill works

The skill inspects application structure and package manifests to recommend multi-stage Dockerfiles optimized for size and cache efficiency. It generates docker-compose services with networks, named volumes, restart policies, and healthchecks, and suggests container patterns for MongoDB, Redis, and other dependencies. It also validates common pitfalls like missing .dockerignore, incorrect ports, or absent health endpoints.

When to use it

  • You need a multi-stage Dockerfile for NestJS or Next.js to optimize build size and startup time.
  • You want a docker-compose setup for development with live reload or for production with persisted volumes and health checks.
  • You need to containerize MongoDB or Redis with secure environment variable handling and restart policies.
  • You want guidance on container networking, service isolation, and named volumes.
  • You need to add health checks, restart policies, or secrets to an existing compose stack.

Best practices

  • Use multi-stage builds to keep runtime images small and only include production artifacts.
  • Leverage layer caching by ordering COPY and dependency installation steps carefully.
  • Add a .dockerignore to exclude dev files and node_modules from builds.
  • Use named volumes for persistent data and bind mounts only in development.
  • Define healthchecks and restart policies to improve resilience and orchestration behavior.

Example use cases

  • Create a Dockerfile for a NestJS API using a deps/builder/runner multi-stage pattern to produce a lean production image.
  • Set up docker-compose for local Next.js development with volume mounts and hot reload, and a separate production compose file with named volumes.
  • Compose file that brings up an app, a MongoDB service with auth and a persisted volume, and a Redis cache.
  • Add healthcheck configuration to services so load balancers and orchestrators can detect readiness.
  • Optimize a CI pipeline by caching node_modules layer and using deterministic builds for reproducible images.

FAQ

Should I use bind mounts or named volumes in production?

Use named volumes in production for persistent data. Reserve bind mounts for development where live-reload and source editing are needed.

How do I keep image size small for Node apps?

Use multi-stage builds, choose slim or alpine base images, copy only built artifacts into the final stage, and use .dockerignore to exclude unnecessary files.