# Docker & Containerization (Go) > Dockerfile, multi-stage builds, การปรับแต่ง image, docker-compose, การจัดการ container - 20 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Go](https://sharpskill.dev/th/technologies/go/interview-questions.md) ## 1. เหตุผลหลักในการใช้ multi-stage build สำหรับแอปพลิเคชัน Go คืออะไร? **คำตอบ** Multi-stage build แยกสภาพแวดล้อมการคอมไพล์ออกจาก image สุดท้าย โดย stage ของ build จะมี Go SDK ครบชุด (หลายร้อย MB) ขณะที่ image สุดท้ายมีเพียง binary ที่คอมไพล์แล้วเท่านั้น ซึ่งช่วยลดขนาด image ลงอย่างมาก (จากประมาณ 800MB เหลือไม่กี่ MB) และลดพื้นผิวการโจมตีด้วยการกำจัด build tools ที่ไม่จำเป็นในการใช้งานจริง ## 2. ควรใช้ base image ใดสำหรับแอปพลิเคชัน Go ในการใช้งานจริงเพื่อลดขนาดและพื้นผิวการโจมตี? **คำตอบ** image scratch เป็น image ว่างเปล่าที่ไม่มีระบบปฏิบัติการ Go คอมไพล์เป็น binary แบบ static ที่ไม่ต้องใช้ libc หรือ dependency ของระบบอื่น ๆ จึงสามารถใช้ scratch ได้ ซึ่งสร้าง image ที่เล็กที่สุดเท่าที่จะเป็นไปได้ (ไม่กี่ MB) และให้ความปลอดภัยสูงสุดเพราะไม่มีเครื่องมือหรือ shell ที่สามารถถูกใช้โจมตีได้ Distroless และ alpine เป็นทางเลือกที่ใช้ได้แต่เหมาะสมน้อยกว่า ## 3. ต้องใช้ flag การคอมไพล์ Go ใดบ้างเพื่อสร้าง binary ที่เข้ากันได้กับ image scratch? **คำตอบ** CGO_ENABLED=0 ปิดการใช้งาน cgo บังคับให้ Go ใช้การ implement แบบ pure Go สำหรับ package เช่น net และ os/user หากไม่มีสิ่งนี้ binary จะมี dependency แบบ dynamic ไปยัง libc ส่วน GOOS และ GOARCH ระบุแพลตฟอร์มเป้าหมาย flag เหล่านี้รวมกันจะสร้าง binary แบบ static อย่างสมบูรณ์โดยไม่มี dependency ภายนอก ซึ่งเหมาะอย่างยิ่งสำหรับ scratch ## มีอีก 17 คำถาม - จะปรับแต่งการแคช layer ของ Docker เมื่อ build แอปพลิเคชัน Go ได้อย่างไร? - ข้อดีของการใช้ image Google Distroless สำหรับ Go เมื่อเทียบกับ scratch คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Go อื่นๆ - [พื้นฐาน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-basics.md): 25 คำถาม, Junior - [โครงสร้างข้อมูล Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-data-structures.md): 20 คำถาม, Junior - [อินเทอร์เฟซใน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-interfaces.md): 18 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/go/interview-questions/error-handling.md): 20 คำถาม, Junior - [พื้นฐาน Goroutine](https://sharpskill.dev/th/technologies/go/interview-questions/goroutines-basics.md): 20 คำถาม, Junior - [Channels](https://sharpskill.dev/th/technologies/go/interview-questions/channels.md): 22 คำถาม, Junior - [Go Modules](https://sharpskill.dev/th/technologies/go/interview-questions/go-modules.md): 18 คำถาม, Mid-Level - [เซิร์ฟเวอร์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-server.md): 24 คำถาม, Mid-Level - [ไคลเอนต์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [การเข้ารหัส JSON](https://sharpskill.dev/th/technologies/go/interview-questions/json-encoding.md): 20 คำถาม, Mid-Level - [Database/SQL](https://sharpskill.dev/th/technologies/go/interview-questions/database-sql.md): 22 คำถาม, Mid-Level - [แพ็กเกจ context](https://sharpskill.dev/th/technologies/go/interview-questions/context-package.md): 20 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/go/interview-questions/testing.md): 22 คำถาม, Mid-Level - [รูปแบบ Concurrency](https://sharpskill.dev/th/technologies/go/interview-questions/concurrency-patterns.md): 24 คำถาม, Mid-Level - [ไพรมิทีฟการซิงโครไนซ์](https://sharpskill.dev/th/technologies/go/interview-questions/sync-primitives.md): 22 คำถาม, Mid-Level - [เฟรมเวิร์กเว็บ Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-web-frameworks.md): 20 คำถาม, Mid-Level - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/go/interview-questions/rest-api-design.md): 20 คำถาม, Mid-Level - [gRPC](https://sharpskill.dev/th/technologies/go/interview-questions/grpc.md): 22 คำถาม, Mid-Level - [Reflection](https://sharpskill.dev/th/technologies/go/interview-questions/reflection.md): 20 คำถาม, Senior - [การจัดการหน่วยความจำ](https://sharpskill.dev/th/technologies/go/interview-questions/memory-management.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/go/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [Generics](https://sharpskill.dev/th/technologies/go/interview-questions/generics.md): 20 คำถาม, Senior - [Go Design Patterns](https://sharpskill.dev/th/technologies/go/interview-questions/design-patterns.md): 24 คำถาม, Senior - [Microservices](https://sharpskill.dev/th/technologies/go/interview-questions/microservices.md): 24 คำถาม, Senior - [ความปลอดภัยและการยืนยันตัวตน](https://sharpskill.dev/th/technologies/go/interview-questions/security-authentication.md): 24 คำถาม, Senior - [Kubernetes Basics](https://sharpskill.dev/th/technologies/go/interview-questions/kubernetes-basics.md): 22 คำถาม, Senior - [Go ขั้นสูง](https://sharpskill.dev/th/technologies/go/interview-questions/advanced-go.md): 20 คำถาม, Senior - [การพัฒนา CLI](https://sharpskill.dev/th/technologies/go/interview-questions/cli-development.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/go/interview-questions/docker-containerization