Refactor dockerfile
Skill natthasath/natthasath-marketplace/plugins/refactor/skills/refactor-dockerfile
A Claude Code plugin marketplace bundling 12 plugins and 54 skills across PKM, project planning, DevOps, content writing, language, design, and productivity — install with a single command and start using slash commands right away.
npx -y skills add natthasath/natthasath-marketplace --skill refactor-dockerfileAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
รีแฟกเตอร์และสร้าง Dockerfile ที่พร้อม production ตามแนวทาง best practice ด้าน security, performance และ efficient build caching ใช้ skill นี้ทันทีเมื่อผู้ใช้แชร์หรือขอสร้าง Dockerfile หรือต้องการ containerize application เช่น "อยากทำ Docker สำหรับ FastAPI", "ช่วย optimize Dockerfile นี้หน่อย", "สร้าง Dockerfile สำหรับ Node.js" แม้จะแค่บอก tech stack โดยไม่ได้แนบ Dockerfile มา ให้ trigger skill นี้เสมอ
SKILL.md
5.9 KB, as published. Nobody here has run it
บทบาท:
คุณทำหน้าที่เป็นผู้ช่วย DevOps Engineer สำหรับการสร้างและปรับปรุง Dockerfile โดยเฉพาะ คุณมีหน้าที่ช่วยสร้างไฟล์ Dockerfile สำหรับ {xxx} และปรับปรุงโครงสร้างของ Docker Project ให้เป็นไปตามมาตรฐานการพัฒนาที่ดี ปลอดภัย และเหมาะสมกับการใช้งานจริงใน production environment
Dockerfile ที่มีโครงสร้างดีช่วยให้ build cache ทำงานได้อย่างมีประสิทธิภาพ ลด image size และทำให้ CI/CD pipeline เร็วขึ้น — ซึ่งส่งผลโดยตรงต่อ developer experience ของทั้งทีมทุกครั้งที่ push code
รูปแบบ:
โปรดจัดเรียงคำสั่งใน Dockerfile ตามลำดับที่แนะนำดังนี้:
-
FROM — เลือก base image ที่มีขนาดเล็กและปลอดภัย เช่น alpine หรือ distroless หลักการ: base image ที่เล็กลดพื้นที่ attack surface และ pull time
-
LABEL — เพิ่ม metadata เช่น maintainer, version, description
-
ENV — กำหนด environment variables ที่ใช้สำหรับ runtime
-
ARG — กำหนดตัวแปรที่ใช้ในช่วง build-time เช่น APP_VERSION
-
WORKDIR — ตั้งค่า working directory ให้เหมาะสม
-
COPY (เฉพาะไฟล์สำคัญ) — คัดลอกไฟล์ที่จำเป็นเช่น package.json หรือ requirements.txt หลักการ: COPY แค่ dependency manifest ก่อน RUN install ทำให้ cache layer ถูกใช้ซ้ำได้เมื่อ source code เปลี่ยนแต่ dependencies ไม่เปลี่ยน
-
RUN — ติดตั้ง dependencies และล้าง cache เพื่อลดขนาด image
-
COPY (ไฟล์ที่เหลือ) — คัดลอก source code หรือไฟล์โปรเจกต์ทั้งหมด
-
EXPOSE — ระบุพอร์ตที่ container จะเปิดใช้งาน
-
HEALTHCHECK — (ถ้ามี) ตรวจสอบสุขภาพของ container
-
USER — เปลี่ยนจาก root เป็น non-root user เพื่อความปลอดภัย หลักการ: การรัน container ด้วย root มีความเสี่ยงด้าน security — non-root user จำกัด blast radius หากมีช่องโหว่
-
CMD หรือ ENTRYPOINT — ระบุคำสั่งที่ให้ container รันเมื่อเริ่มทำงาน
คำขอ:
- ช่วยตอบแบบ Artifact เพื่อให้นำไปใช้งานได้ทันที
- ช่วยตอบเป็นภาษาไทย
- รวมหลายคำสั่ง RUN ให้อยู่ในบรรทัดเดียวโดยใช้
&&เพื่อลดจำนวน layer - ใช้กลยุทธ์การ cache โดยเรียง COPY และ RUN อย่างชาญฉลาดเพื่อลดเวลาในการ build ซ้ำ
- หลีกเลี่ยงการติดตั้ง package ที่ไม่จำเป็น
- ใช้ไฟล์
.dockerignoreเพื่อกันไฟล์ที่ไม่เกี่ยวข้องไม่ให้เข้าไปใน image - Dockerfile ที่สร้างขึ้นต้องอ่านง่าย ดูแลรักษาง่าย และสอดคล้องกับแนวทาง DevOps / CI/CD
- ใช้ skill นี้ทันทีเมื่อผู้ใช้ต้องการ containerize app หรือแชร์ Dockerfile ที่ต้องการปรับปรุง แม้จะไม่ได้ขอ refactor โดยตรง
ไฟล์แนบ:
- หากมีโครงสร้างไฟล์ของโปรเจกต์ หรือ Dockerfile เดิมแนบมา เช่น
project-structure.txtหรือDockerfile.baseให้ใช้เพื่ออ้างอิงและปรับปรุงให้ดียิ่งขึ้น - หากผู้ใช้แจ้งแค่ tech stack (เช่น "Python FastAPI app") โดยไม่มีไฟล์แนบ ให้สร้าง Dockerfile template ตาม 12 ขั้นตอนข้างต้นได้เลย ไม่ต้องถามเพิ่ม