Docker เป็นแอปพลิเคชั่นที่อนุญาตให้ปรับใช้ซอฟต์แวร์ภายในคอนเทนเนอร์เสมือน มันถูกเขียนด้วยภาษาโปรแกรม Go ในบทช่วยสอนนี้ คุณจะได้เรียนรู้วิธีติดตั้ง Docker บน CentOS 7
CentOS 7 ต้องการ RAM อย่างน้อย 1 GB
ก่อนอื่น ตรวจสอบให้แน่ใจว่าเรากำลังใช้ระบบที่สะอาดหมดจด อัพเดททุกอย่าง
yum update
ก่อนอื่น เราจะต้องตรวจสอบให้แน่ใจว่าไม่มี Docker เวอร์ชันเก่าติดตั้งอยู่ หากคุณแน่ใจว่าไม่มี คุณสามารถข้ามคำสั่งต่อไปนี้ได้ หากคุณไม่แน่ใจ คุณควรเรียกใช้สิ่งต่อไปนี้เพื่อความปลอดภัย
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
ตอนนี้เราลบเวอร์ชั่นเก่าแล้ว เราสามารถติดตั้งแพ็คเกจที่จำเป็นได้
yum-utils will provide the yum-config-manager. The device-mapper-persistent-data and lvm2 packages are necessary for the devicemapper storage driver:
yum install -y yum-utils device-mapper-persistent-data lvm2
ตอนนี้เราสามารถตั้งค่าที่เก็บ Docker
yum-config-manager -y --add-repo https://download.docker.com/linux/centos/docker-ce.repo
ตอนนี้เราพร้อมที่จะติดตั้ง Docker CE เวอร์ชันล่าสุดแล้ว
yum install docker-ce
หมายเหตุ: *หากต้องการติดตั้งเวอร์ชันเฉพาะ ให้ผนวก -<VERSION> ต่อท้ายคำสั่งติดตั้ง ตัวอย่างเช่น ในการติดตั้งเวอร์ชัน 18.03 ให้ใช้สิ่งต่อไปนี้
yum install docker-ce-18.03.0.ce
หากคุณไม่ต้องการเรียกใช้ Docker ในฐานะผู้ใช้ root ให้สร้างผู้ใช้ที่ไม่ใช่ root
adduser user
จากนั้น เพิ่มผู้ใช้รายนี้ในกลุ่ม Docker
usermod -aG docker user
ตอนนี้เริ่มบริการ Docker
systemctl start docker
คุณสามารถใช้การทดสอบ hello-world ตรวจสอบว่า Docker จะทำงานบนระบบของคุณหรือไม่
docker run hello-world
เมื่อสำเร็จ ข้อความต้อนรับจะส่งคืน
Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/userguide/
ตอนนี้เรารู้แล้วว่า Docker ใช้งานได้ เรามาเปิดใช้งานกันเมื่อระบบบูทเครื่องกัน
chkconfig docker on
ส่วนวิธีสร้าง Container ดูใน blog ถัดไปนะครับ