| name | docker |
| description | Container-based development for isolated, reproducible environments. Use when running npm commands, installing packages, executing code, or managing project dependencies. Trigger phrases include "npm install", "run the build", "start the server", "install package", or any code execution request. |
Docker Development Skill
Execute all package installations and code execution inside Docker containers. This keeps the host machine clean and ensures consistent environments across projects.
Core Principle
NEVER run npm, node, npx, or project scripts directly on the host machine.
Instead, use docker exec or ensure the container is running the dev server.
Pre-Flight Check (MANDATORY)
Before running ANY npm/node command, Claude Code MUST verify the container is running.
Run this check first:
docker ps --filter "name=<project-name>" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
Expected output:
NAMES STATUS PORTS
<project-name>-dev-1 Up X minutes 0.0.0.0:3000->3000/tcp
If container is NOT running:
cd /path/to/your/project
docker-compose --profile dev up dev -d
docker ps --filter "name=<project-name>"
If container shows "Exited":
docker logs <project-name>-dev-1 --tail 20
docker-compose --profile dev down
docker-compose --profile dev up dev -d
Quick Reference
Check Container Status
docker ps --filter "name=<project-name>"
docker logs <project-name>-dev-1 --tail 50
curl -s http://localhost:3000 > /dev/null && echo "Server running" || echo "Server not running"
Start/Stop Containers
docker-compose --profile dev up dev -d
docker-compose --profile dev down
docker-compose --profile dev restart dev
docker-compose --profile dev up dev -d --build
Execute Commands Inside Container
docker exec -it <project-name>-dev-1 npm install <package-name>
docker exec -it <project-name>-dev-1 npm install -D <package-name>
docker exec -it <project-name>-dev-1 npm test
docker exec -it <project-name>-dev-1 npm run typecheck
docker exec -it <project-name>-dev-1 npm run lint
docker exec -it <project-name>-dev-1 npm run build
docker exec -it <project-name>-dev-1 /bin/sh
docker exec -it <project-name>-dev-1 <command>
When to Use Docker exec
| Operation | Use docker exec? | Reason |
|---|
npm install | ā
Yes | Packages install in container |
npm run dev | ā No | Already running via docker-compose |
npm test | ā
Yes | Tests run in container environment |
npm run build | ā
Yes | Build happens in container |
git commands | ā No | Git runs on host (manages files) |
| File editing | ā No | Volume mount syncs automatically |
| Database migrations | ā
Yes | Uses container's Node environment |
Container Architecture
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā HOST (macOS/Linux/Windows) ā
ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā Docker Container (<project-name>-dev-1) ā ā
ā ā ā ā
ā ā Node 20 Alpine ā ā
ā ā āāā node_modules/ (container-only) ā ā
ā ā āāā Dev server (port 3000) ā ā
ā ā ā ā
ā ā Volume Mounts: ā ā
ā ā āāā .:/app (source code sync) ā ā
ā ā āāā node_modules:/app/node_modules (persist deps) ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā ā¼ ā
ā Port 3000 mapped ā
ā ā ā
ā ā¼ ā
ā http://localhost:3000 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Volume Mount Behavior
The docker-compose.yml mounts the project directory into the container:
volumes:
- .:/app
- /app/node_modules
What this means:
- Source code changes on host are immediately visible in container
node_modules/ in container is separate from any on host
- Hot reload works automatically with most frameworks
Troubleshooting
Container Not Running
docker ps -a --filter "name=<project-name>"
docker logs <project-name>-dev-1
docker-compose --profile dev up dev -d
Port Already in Use
lsof -i :3000
Module Not Found Errors
docker-compose --profile dev down
docker-compose --profile dev build --no-cache dev
docker-compose --profile dev up dev -d
File Changes Not Reflecting
docker inspect <project-name>-dev-1 | grep -A 10 "Mounts"
docker-compose --profile dev restart dev
Project Configuration
After installing this skill, update the placeholders for your project:
| Setting | Example Value |
|---|
| Container name | my-app-dev-1 |
| Port | 3000 (or your app's port) |
| Node version | 20 (Alpine) |
| Dev command | npm run dev -- --host 0.0.0.0 |
Environment Variables
Required env vars are loaded from .env file via docker-compose.
If a command needs a specific env var:
docker exec -it -e MY_VAR=value <project-name>-dev-1 <command>
Best Practices
- Always check container status before running commands
- Use
docker exec for all npm/node operations
- Let volume mounts handle file syncing (no manual copying)
- Rebuild image after changing
package.json or Dockerfile
- Check logs if something isn't working
Integration with Claude Code
When Claude Code needs to:
| Task | Action |
|---|
| Install dependency | docker exec -it <project-name>-dev-1 npm install <pkg> |
| Run tests | docker exec -it <project-name>-dev-1 npm test |
| Check types | docker exec -it <project-name>-dev-1 npm run typecheck |
| Build project | docker exec -it <project-name>-dev-1 npm run build |
| Start dev server | Container already runs it via docker-compose |
| Edit files | Edit directly (volume mount syncs) |
| Git operations | Run on host (not in container) |
Sample docker-compose.yml
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
env_file:
- .env
restart: unless-stopped
dev:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
env_file:
- .env
profiles:
- dev
Sample Dockerfile.dev
FROM node:20-alpine
WORKDIR /app
# Install dependencies for native modules
RUN apk add --no-cache python3 make g++
# Copy package files and any scripts needed for postinstall
COPY package*.json ./
COPY scripts/ ./scripts/
# Install all dependencies
RUN npm install
# Copy source code
COPY . .
# Expose port
EXPOSE 3000
# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=3000
ENV NODE_ENV=development
# Start development server
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]