using-docker
SKILL.md
Using Docker & Docker Compose
When to use this skill
- When the user mentions "Docker", "Container", "Image", "Volume", or "Compose".
- When the user wants to ensure a consistent development environment across machines.
- When deploying to container-based services (ECS, DigitalOcean App Platform, Render).
- When the user asks to write a
Dockerfile.
Workflow
- Dockerfile Creation:
- Select Base Image:
FROM node:20-alpine(use alpine for size). - Set Workdir:
WORKDIR /app. - Install Deps: Copy
package.json->RUN npm ci. - Copy Code:
COPY . .. - Build/Start:
RUN npm run build(if needed) ->CMD ["npm", "start"].
- Select Base Image:
- Docker Compose:
- Create
docker-compose.yml. - Define services (app, db, redis).
- Map ports (
ports: ["3000:3000"]). - Define environment variables (
env_file: .env).
- Create
- Execution:
- Build:
docker compose build. - Up:
docker compose up -d(detached). - Logs:
docker compose logs -f.
- Build:
Instructions
Standard Node.js Dockerfile (Production Ready)
# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: Runner
FROM node:20-alpine
WORKDIR /app
COPY /app/dist ./dist
COPY /app/package*.json ./
COPY /app/node_modules ./node_modules
ENV NODE_ENV=production
EXPOSE 3000
CMD ["npm", "start"]
Docker Compose Example
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:15-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Best Practices
- Layer Caching: Always copy
package.jsonand install dependencies before copying source code. This prevents re-installing modules when only code changes. - Micro-containers: Use
alpineorslimtags to minimize image size (~10x smaller). - Security: Don't run as root (use
USER nodein final stage if possible).
Resources
Weekly Installs
2
Repository
pauloviccs/vicc…screatorGitHub Stars
3
First Seen
14 days ago
Security Audits
Installed on
trae2
gemini-cli2
claude-code2
github-copilot2
codex2
kimi-cli2