Why use docker to make webserver
# Lemon 8 Howtoo # webserver # Web Site Writing Basics # docker
Docker is a tool that allows us to "pack" the software into a box called Container so that our applications run exactly the same everywhere, whether on your notebook, your friend's machine, or on a real server, without worrying that "I can run but you can't run" because of the problem of Windows, Mac or Library versions mismatch. 1. Docker's main idea: Container vs Virtual Machine In the old days, if we wanted to simulate the environment, we had to use a Virtual Machine (VM), which consumes very high machine resources because it has to run a whole new OS, but Docker instead uses resource sharing from the main OS, making it much lighter and faster. Virtual Machine (VM) Docker Container is slow to boot (in minutes), boot very fast (in seconds), use of resources, eat RAM and CPU, save a large resource (many GB), small (main MB) 2. Technical terms to know (unconfused) to talk to Dev people about. There are three words you will often hear: Docker Image: Like a "blueprint" or a CD installation that combines code, runtime, and settings. Docker Container: The image is actually "run" (if the Image is a blueprint, the Container house is the completed house). Docker Hub: It's like an App Store or GitHub for storing images for free, such as MySQL, Python, or Nginx3. Why does anyone use Docker? Consistency: Be sure that the environment is the same everywhere. Isolation: Each container is clearly separated. If one is broken, the other still works. Scalability: Extend the system very easily. Want to add 10 more Web Servers, just one command. CI / CD Friendly: Fits modern automation. In a nutshell: Docker is a "container for software" that makes the programmer's life easier because you don't have to sit around to install a repetitive environment.
จากประสบการณ์การใช้งาน Docker ในการตั้งค่า Webserver จริง ๆ พบว่าการใช้ Docker ช่วยลดเวลาการทำงานลงได้อย่างมาก เหมาะสำหรับมือใหม่และทีมงานที่ต้องแชร์สภาพแวดล้อมร่วมกัน เพราะ Docker จะจัดการทุกอย่างไว้ใน Container ทำให้มั่นใจได้ว่าเว็บเซิร์ฟเวอร์ที่รันบนเครื่องของเราจะเหมือนกันเป๊ะไม่ว่าจะไปใช้งานบนเครื่องใดก็ตาม ข้อดีที่เห็นได้ชัดคือ ไม่ต้องกังวลเรื่องการติดตั้งและกำหนดค่าเครื่องมือและไลบรารีต่าง ๆ หลายครั้งที่ต้องตั้งค่าซ้ำซ้อนและเจอปัญหาระบบไม่ตรงกัน ซึ่ง Docker ช่วยแก้ไขปัญหานี้ได้ดีมาก นอกจากนี้ Docker ยังทำให้การรันเว็บเซิร์ฟเวอร์อย่าง Nginx หรือ Node.js ในเครื่องพัฒนาและเซิร์ฟเวอร์จริงเป็นไปอย่างรวดเร็วและคล่องตัว ในการลองใช้งานจริง พบว่า Docker Container ใช้ทรัพยากรน้อยกว่าการรัน Virtual Machine อย่างเห็นได้ชัด เครื่องไม่หน่วงและเปิดใช้งานได้เร็วมาก ทำให้การทดสอบเว็บเซิร์ฟเวอร์หลายเวอร์ชันสามารถทำได้พร้อมกันอย่างไม่ยุ่งยาก อีกเรื่องที่ประทับใจคือ Docker Hub ที่เป็นคลังเก็บ Docker Image ฟรี ๆ ทำให้การติดตั้งซอฟต์แวร์ยอดนิยม เช่น MySQL, Python, Nginx ทำได้ง่ายดายแค่ไม่กี่คำสั่ง ช่วยประหยัดเวลาและลดความผิดพลาดในการติดตั้ง ท้ายสุด การจัดการเว็บเซิร์ฟเวอร์ที่อยู่ใน Container ช่วยให้การขยายระบบ หรือ Scaling ทำได้สะดวกมาก เช่น ต้องการเพิ่ม Web Server หลายเครื่องก็เหมือนสั่งรัน Container เพิ่มขึ้นหลายตัวโดยไม่ต้องตั้งค่าใหม่อีกครั้ง ซึ่งเหมาะกับงานระบบที่ต้องการความยืดหยุ่นสูง ถ้าคุณเป็นนักพัฒนาหรือนักดูแลระบบที่กำลังมองหาวิธีจัดการเว็บเซิร์ฟเวอร์ที่ง่ายและรวดเร็ว Docker เป็นทางเลือกที่ไม่ควรมองข้ามจริง ๆ
