<< All versions
Skill v1.0.1
currentAutomated scan100/100pluginagentmarketplace/custom-plugin-nodejs/docker-deployment
4 files
──Details
PublishedMay 14, 2026 at 09:37 PM
Content Hashsha256:c04b56f9f33d51a3...
Git SHAadbdacbf26cb
Bump Typepatch
──Files
Files (1 file, 7.0 KB)
SKILL.md7.0 KBactive
SKILL.md · 393 lines · 7.0 KB
version: "1.0.1" 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:
- Create Dockerfile - Define container image
- Build Image -
docker build -t myapp . - Run Container -
docker run -p 3000:3000 myapp
Core Concepts
Basic Dockerfile
dockerfile
FROM node:18-alpineWORKDIR /appCOPY package*.json ./RUN npm ci --only=productionCOPY . .EXPOSE 3000CMD ["node", "src/index.js"]
Multi-Stage Build (Optimized)
dockerfile
# Build stageFROM node:18-alpine AS builderWORKDIR /appCOPY package*.json ./RUN npm ci --only=productionCOPY . .# Production stageFROM node:18-alpineWORKDIR /app# Copy from builderCOPY --from=builder /app/node_modules ./node_modulesCOPY --from=builder /app .# Create non-root userRUN addgroup -g 1001 -S nodejs && \adduser -S nodejs -u 1001USER nodejsEXPOSE 3000HEALTHCHECK --interval=30s --timeout=3s \CMD node healthcheck.js || exit 1CMD ["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.ymlversion: '3.8'services:app:build: .ports:- "3000:3000"environment:- NODE_ENV=production- DATABASE_URL=postgresql://db:5432/myapp- REDIS_URL=redis://redis:6379depends_on:- db- redisrestart: unless-stoppeddb:image: postgres:15-alpineenvironment:- POSTGRES_USER=myapp- POSTGRES_PASSWORD=secret- POSTGRES_DB=myappvolumes:- postgres-data:/var/lib/postgresql/dataredis:image: redis:7-alpinevolumes:- redis-data:/datanginx:image: nginx:alpineports:- "80:80"volumes:- ./nginx.conf:/etc/nginx/nginx.conf:rodepends_on:- appvolumes:postgres-data:redis-data:
Docker Compose Commands
bash
# Start servicesdocker-compose up -d# View logsdocker-compose logs -f app# Stop servicesdocker-compose down# Rebuild imagesdocker-compose up -d --build# Scale servicesdocker-compose up -d --scale app=3
.dockerignore
node_modulesnpm-debug.log.git.gitignore.env.env.local.vscode*.mdtestscoverage.githubDockerfiledocker-compose.yml
Docker Commands
bash
# Build imagedocker build -t myapp:latest .# Run containerdocker run -d -p 3000:3000 --name myapp myapp:latest# View logsdocker logs -f myapp# Enter containerdocker exec -it myapp sh# Stop containerdocker stop myapp# Remove containerdocker rm myapp# List imagesdocker images# Remove imagedocker rmi myapp:latest# Prune unused resourcesdocker system prune -a
Environment Variables
dockerfile
# In DockerfileENV NODE_ENV=productionENV PORT=3000# Or in docker-compose.ymlenvironment:- NODE_ENV=production- PORT=3000# Or from .env fileenv_file:- .env.production
Volumes for Persistence
yaml
services:app:volumes:- ./logs:/app/logs # Bind mount- node_modules:/app/node_modules # Named volumevolumes:node_modules:
Health Checks
dockerfile
# In DockerfileHEALTHCHECK --interval=30s --timeout=3s --start-period=5s \CMD node healthcheck.js || exit 1
javascript
// healthcheck.jsconst http = require('http');const options = {host: 'localhost',port: 3000,path: '/health',timeout: 2000};const request = http.request(options, (res) => {console.log(`STATUS: ${res.statusCode}`);process.exit(res.statusCode === 200 ? 0 : 1);});request.on('error', (err) => {console.log('ERROR:', err);process.exit(1);});request.end();
Image Optimization
dockerfile
# Use Alpine (smaller base image)FROM node:18-alpine # 180MB vs node:18 (1GB)# Multi-stage build (remove build dependencies)# Use .dockerignore (exclude unnecessary files)# npm ci instead of npm install (faster, deterministic)# Only production dependenciesRUN npm ci --only=production# Combine RUN commands (fewer layers)RUN apk add --no-cache git && \npm ci && \apk del git
Production Best Practices
dockerfile
FROM node:18-alpine# Don't run as rootRUN addgroup -g 1001 -S nodejs && \adduser -S nodejs -u 1001WORKDIR /appCOPY --chown=nodejs:nodejs package*.json ./RUN npm ci --only=productionCOPY --chown=nodejs:nodejs . .USER nodejs# Health checkHEALTHCHECK CMD node healthcheck.js || exit 1# Use node instead of npm start (better signal handling)CMD ["node", "src/index.js"]
Docker Hub Deployment
bash
# Logindocker login# Tag imagedocker tag myapp:latest username/myapp:1.0.0docker tag myapp:latest username/myapp:latest# Push to Docker Hubdocker push username/myapp:1.0.0docker push username/myapp:latest# Pull from Docker Hubdocker pull username/myapp:latest
CI/CD with GitHub Actions
yaml
name: Docker Build & Deployon:push:branches: [main]jobs:build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3- uses: docker/setup-buildx-action@v2- uses: docker/login-action@v2with:username: ${{ secrets.DOCKER_USERNAME }}password: ${{ secrets.DOCKER_PASSWORD }}- uses: docker/build-push-action@v4with:push: truetags: username/myapp:latestcache-from: type=ghacache-to: type=gha,mode=max
Common Issues & Solutions
Node modules caching
dockerfile
# Cache node_modules layerCOPY package*.json ./RUN npm ciCOPY . . # This doesn't rebuild node_modules
Signal handling
dockerfile
# Use node directly (not npm)CMD ["node", "src/index.js"]# In app: Handle SIGTERMprocess.on('SIGTERM', () => {server.close(() => process.exit(0));});
When to Use
Use Docker deployment when:
- Need consistent environments (dev, staging, prod)
- Deploying microservices
- Want easy scaling and orchestration
- Using cloud platforms (AWS, GCP, Azure)
- Implementing CI/CD pipelines
Related Skills
- Express REST API (containerize APIs)
- Database Integration (multi-container setup)
- Testing & Debugging (test in containers)
- Performance Optimization (optimize images)