refactor-dockerfile

Generates and refactors production-oriented Dockerfiles following security and build caching best practices.

1|Updated Jun 29, 2026
One-click install
npx skills add https://github.com/natthasath/natthasath-marketplace --skill refactor-dockerfile-natthasath
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-dockerfile
Source: https://github.com/natthasath/natthasath-marketplace/tree/main/plugins/refactor/skills/refactor-dockerfile
Command: npx skills add https://github.com/natthasath/natthasath-marketplace --skill refactor-dockerfile-natthasath

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Dockerfiles that are secure, small, and fast to rebuild requires knowing many best practices around layer ordering, caching, base image selection, and non-root users. This Skill applies a proven 12-step Dockerfile structure so your containers are production-ready without trial and error. ## Core Features & Use Cases - Dockerfile Generation from Scratch: Provide just a tech stack (e.g., "Python FastAPI app") and receive a complete Dockerfile template following the 12-step ordering from FROM to CMD/ENTRYPOINT. - Dockerfile Refactoring: Share an existing Dockerfile and get it restructured for better build caching, smaller image size, and improved security. - Security & Performance Best Practices: Enforces non-root USER, minimal base images (alpine/distroless), merged RUN commands with &&, .dockerignore usage, and smart COPY/RUN ordering for cache reuse. - Use Case: You have a Node.js app to containerize for CI/CD. Invoke the skill with your stack, and receive a layered Dockerfile where dependency manifests are copied before source code so rebuilds stay fast. ## Quick Start Run /refactor-dockerfile with the path to your Dockerfile or your tech stack, for example "/refactor-dockerfile Python FastAPI app", to get a production-ready Dockerfile.

Frequently Asked Questions about refactor-dockerfile

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a production-ready Dockerfile for a FastAPI app?▼

Invoke /refactor-dockerfile with your tech stack, such as "Python FastAPI app", and it generates a complete Dockerfile template. The output follows a 12-step structure from base image selection through CMD, with no extra input files required.

How to optimize Docker build caching in a Dockerfile?▼

Copy only dependency manifests like package.json or requirements.txt before running the install step, then copy the remaining source code afterward. This ordering lets Docker reuse the dependency layer when only source code changes, speeding up rebuilds.

Can I refactor an existing Dockerfile instead of creating a new one?▼

Yes, attach your existing Dockerfile or project structure file and the skill uses it as a reference to restructure and improve. It applies the same 12-step ordering, security hardening, and caching strategy to your current configuration.

Why should a Docker container run as a non-root user?▼

Running containers as root increases security risk because a vulnerability gives attackers full container privileges. Switching to a non-root USER limits the blast radius if the application is compromised, which is why the skill includes it as a standard step.

What base images does this Dockerfile approach recommend?▼

It recommends small, secure base images such as alpine or distroless variants. Smaller base images reduce the attack surface and shorten image pull times in CI/CD pipelines.