- Home
- Skills
- DevOps & Cloud
- Docker & Compose Production Hardener
Docker & Compose Production Hardener
by LegitAntiAA
Turn development Dockerfiles and docker-compose.yml into lean, secure production setups: multi-stage builds, non-root users, .dockerignore, healthchecks, and resource limits.
$5
Docker & Compose Production Hardener
Example session with this skill installed
Harden my Dockerfile and docker-compose.yml for production — shrink the image size, remove root privileges, and add healthchecks.
- Read your context and instructions
- Compiled the docker & compose
I have audited your container setup. I refactored the Dockerfile into a multi-stage build using node:20-alpine, implemented a non-root appuser, and added security constraints to your Compose file.
Hardening Audit Summary
| Feature | Before | After |
|---|---|---|
| Base Image | node:20 (Bloated) | node:20-alpine (Minimal) |
| Build Pattern | Single-stage | Multi-stage (Build vs Runtime) |
| User | root | appuser (Non-privileged) |
| Layer Caching | Inefficient | Optimized (Lockfiles first) |
| Capabilities | All enabled | cap_drop: ["ALL"] |
| Privileges | Standard | no-new-privileges:true |
# Stage 1: Builder
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: Runtime
FROM node:20-alpine
LABEL maintainer="production-hardener"
WORKDIR /app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
COPY package.json .
USER appuser
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --quiet --tries=1 --spider http://localhost:3000/health || exit 1
EXPOSE 3000
CMD ["node", "dist/main.js"]
services:
web:
build: .
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
ports:
- "127.0.0.1:3000:3000"
Next steps
- Run
docker compose build --no-cacheto verify the new multi-stage pipeline. - Check application logs to ensure the service starts correctly as
appuser. - Verify the healthcheck status using
docker ps.
Connects securely to your tools. The creator never sees your data.
About this skill
Development-grade Docker configurations often leak secrets, run as root, and ship with hundreds of unnecessary vulnerabilities in bloated base images. This skill audits your container setup and applies production-hardening patterns to shrink images and lock down the runtime.
What it does
- Multi-stage refactoring separates build-time dependencies from the final runtime to minimize attack surface and image size.
- Security hardening implements non-root users, drops kernel capabilities, and prevents privilege escalation.
- Layer optimization restructures commands to maximize cache hits and clears package manager caches within the same layer.
- Context filtering generates or updates
.dockerignoreto prevent sensitive files like.gitor.envfrom entering the build context. - Resource management adds CPU/memory limits and healthchecks to ensure service stability and observability.
How it works
- Audit identifies issues in
Dockerfile,docker-compose.yml, and.dockerignorefiles. - Hardening applies multi-stage builds, pins image versions, and configures secure defaults.
- Compose lockdown restricts container capabilities and binds ports to localhost where applicable.
- Summary provides a comparison table showing improvements in security posture and image efficiency.
Frameworks & tools
Works with any language or framework utilizing Docker, including Node.js, Python, Go, and Rust. Compatible with Docker Engine and Docker Compose.
Why this beats prompting it yourself
Generic prompts often miss the nuances of layer caching or fail to drop all unnecessary kernel capabilities. This skill uses a systematic checklist to ensure no security flags or cleanup steps are forgotten during the refactoring process.
Use cases
- Shrinking a 1GB Python or Node.js image into a lean, production-ready version.
- Securing a legacy container that currently runs as root.
- Preparing a Docker Compose stack for deployment behind a reverse proxy.
- Preventing secrets and local dev junk from bloating the build context.
Known limitations
Requires existing Docker or Compose files to audit. Does not automatically fix application-level code that requires root permissions to execute.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 17 days ago
Permissions
What's inside
Frequently Asked Questions
New in DevOps & Cloud
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for DevOps & Cloud.