Containerization

From Sir-chawakorn/power-ranger-toolkit · View interactive version

Containerization is an AI agent skill from the GitHub repository Sir-chawakorn/power-ranger-toolkit. Docker and Kubernetes workflows for containerization. Use for building containers, orchestration, and cloud-native deployments.

How to use this skill

Skill file

🐳 Containerization Skill

Docker Basics

Dockerfile

# Multi-stage build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]

docker-compose.yml

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://db:5432/app
    depends_on:
      - db
  
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

Docker Commands

# Build
docker build -t myapp:latest .

# Run
docker run -d -p 3000:3000 --name myapp myapp:latest

# Compose
docker-compose up -d
docker-compose down

# Clean up
docker system prune -a

Kubernetes Basics

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myapp:latest
          ports:
            - containerPort: 3000
          resources:
            limits:
              memory: "256Mi"
              cpu: "500m"

Service

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 3000
  type: LoadBalancer

K8s Commands

# Apply configs
kubectl apply -f deployment.yaml

# Get resources
kubectl get pods
kubectl get services

# Logs & Debug
kubectl logs pod-name
kubectl exec -it pod-name -- /bin/sh

# Scale
kubectl scale deployment myapp --replicas=5

Best Practices

| Practice | Description |

|----------|-------------|

| .dockerignore | Exclude node_modules, .git |

| Multi-stage | Smaller production images |

| Non-root | Run as non-root user |

| Health checks | Add HEALTHCHECK directive |

| Resource limits | Set CPU/memory limits |


Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.