
Docker Deployment
Containerize a Node.js service with multi-stage images, non-root users, health checks, and Compose so you can ship the same build locally and in prod.
Install
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-nodejs --skill docker-deploymentWhat is this skill?
- Three-step quick start: Dockerfile → docker build → docker run with port publish
- Production-oriented multi-stage Dockerfile pattern separating install/build from runtime
- npm ci --only=production in image layers for deterministic dependency installs
- Non-root nodejs user (uid 1001) and HEALTHCHECK stub for production hardening
- Alpine-based node:18 images for smaller attack surface and faster pulls
Adoption & trust: 1 installs on skills.sh; 2 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
Shipping a Node.js app to production is the canonical moment solo builders need a reproducible container workflow; Docker is the default artifact between “works on my machine” and a hosted service. Launch prep under Ship is where Dockerfile, image build, port mapping, and first deploy commands belong—not ad-hoc terminal notes during Build.
Common Questions / FAQ
Is Docker Deployment safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Docker Deployment
nodejs_skill: docker-deployment # docker-deployment Guide #!/usr/bin/env python3 import json print(json.dumps({"skill": "docker-deployment"}, indent=2)) --- name: docker-deployment description: Containerize and deploy Node.js applications with Docker including multi-stage builds, Docker Compose, and production optimization sasmp_version: "1.3.0" bonded_agent: 01-nodejs-fundamentals bond_type: PRIMARY_BOND --- # Docker Deployment Skill Master containerizing and deploying Node.js applications with Docker for consistent, portable deployments. ## Quick Start Dockerize Node.js app in 3 steps: 1. **Create Dockerfile** - Define container image 2. **Build Image** - `docker build -t myapp .` 3. **Run Container** - `docker run -p 3000:3000 myapp` ## Core Concepts ### Basic Dockerfile ```dockerfile FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "src/index.js"] ``` ### Multi-Stage Build (Optimized) ```dockerfile # Build stage FROM node:18-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . # Production stage FROM node:18-alpine WORKDIR /app # Copy from builder COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app . # Create non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 USER nodejs EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s \ CMD node healthcheck.js || exit 1 CMD ["node", "src/index.js"] ``` ## Learning Path ### Beginner (1-2 weeks) - ✅ Understand Docker basics - ✅ Create simple Dockerfile - ✅ Build and run containers - ✅ Manage volumes and networks ### Intermediate (3-4 weeks) - ✅ Multi-stage builds - ✅ Docker Compose - ✅ Environment variables - ✅ Health checks ### Advanced (5-6 weeks) - ✅ Image optimization - ✅ Production best practices - ✅ Container orchestration - ✅ CI/CD integration ## Docker Compose ```yaml # docker-compose.yml version: '3.8' services: app: build: . ports: - "3000:3000" environment: - NODE_ENV=production - DATABASE_URL=postgresql://db:5432/myapp - REDIS_URL=redis://redis:6379 depends_on: - db - redis restart: unless-stopped db: image: postgres:15-alpine environment: - POSTGRES_USER=myapp - POSTGRES_PASSWORD=secret - POSTGRES_DB=myapp volumes: - postgres-data:/var/lib/postgresql/data redis: image: redis:7-alpine volumes: - redis-data:/data nginx: image: nginx:alpine ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro depends_on: - app volumes: postgres-data: redis-data: ``` ### Docker Compose Commands ```bash # Start services docker-compose up -d # View logs docker-compose logs -f app # Stop services docker-compose down # Rebuild images docker-compose up -d --build # Scale services docker-compose up -d --scale app=3 ``` ## .dockerignore ``` node_modules npm-debug.log .git .gitignore .env .env.local .vscode *.md tests coverage .github Dockerfile docker-compose.yml ``` ## Docker Commands ```bash # Build image docker build -t myapp:latest . # Run container docker run -d -p 3000:3000 --name myapp myapp:latest # View logs docker logs -f myapp # Enter container docker exec -it myapp sh # Stop container docker stop myapp # Remove container docker rm myapp # List images docker images # Remove image docker rmi myapp:latest # Prune unused resources docker system prune -a ``` ## Environment Variables ```dockerfile # In Dockerfile ENV NODE_ENV=production ENV PORT=3000 # Or in docker-compose.yml environment: - NODE_ENV=production - PORT=3000 # Or from .env file env_file: - .env.production ``` ## Volumes for Persistence ```yaml services: app: volumes: - ./logs:/app/logs # Bind mount - node_modules:/app/node_modules # Named volume volumes: node_modules: ``` ## Health Checks ```dockerfile # In Dock