ติดตั้ง Docker CE บน Ubuntu 16.04

docker มีการปรับปรุงอยู่เสมอ ทำให้แพ็กเกจใน Ubuntu 16.04 Repository ไม่สามารถใช้คำสั่ง apt-get ติดตั้ง docker เวอร์ชันใหม่ได้

ลองมาดูวิธีการติดตั้ง Docker Repository ซึ่งเป็นของทาง docker.com เอง เพื่อใช้ติดตั้ง docker เวอร์ชันล่าสุด สำหรับทดลองใช้งานคุณสมบัติใหม่ๆ ของ docker กัน

ในที่นี้จะติดตั้ง Docker CE หรือ Community Edition ที่เราสามารถใช้งานได้ฟรี

รันคำสั่ง apt-get update เพื่ออัพเดทแพ็กเกจของ ubuntu ให้เป็นเวอร์ชันล่าสุด

$ sudo apt-get update

ติดตั้ง Docker Repository

รัน apt-get install ติดตั้งแพ็กเกจที่จำเป็นต่อการดาวน์โหลดและติดตั้ง Docker Repository

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

ดาวน์โหลดไฟล์ GPG key อย่างเป็นทางการของ Docker

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

ตรวจสอบ GPG key ที่ติดตั้งว่าถูกต้องไหม โดยดูตัวอักษร 8 ตัวสุดท้าย ใน fingerprint ถ้าถูกต้องจะแสดงผลลัพธ์เหมือนด้านล่าง

$ sudo apt-key fingerprint 0EBFCD88
pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

ติดตั้ง Docker Stable Repository

$ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

รันคำสั่ง apt-get update เพื่ออัพเดทแพ็กเกจทั้งหมดอีกครั้ง หลังติดตั้ง repository ใหม่

$ sudo apt-get update

ติดตั้ง Docker CE

รันคำสั่ง apt-get install ติดตั้ง docker-ce

$ sudo apt-get install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount libltdl7
Suggested packages:
  mountall
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount docker-ce libltdl7
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 30.3 MB of archives.
After this operation, 149 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...

หลังติดตั้งเสร็จเรียบร้อย ทดลองรันคำสั่ง docker version เพื่อแสดงข้อมูลเบื้องต้นของ docker

$ sudo docker version
Client:
 Version:       17.12.1-ce
 API version:   1.35
 Go version:    go1.9.4
 Git commit:    7390fc6
 Built: Tue Feb 27 22:17:40 2018
 OS/Arch:       linux/amd64

Server:
 Engine:
  Version:       17.12.1-ce
  API version:   1.35 (minimum version 1.12)
  Go version:    go1.9.4
  Git commit:    7390fc6
  Built: Tue Feb 27 22:16:13 2018
  OS/Arch:       linux/amd64
  Experimental:  false

ทดสอบรัน docker

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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 ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

ถ้ารันแล้วแสดงผลลัพท์ตามตัวอย่างด้านบน แสดงว่าเราติดตั้ง Docker สำเร็จก พร้อมทดสอบการใช้งานได้ :)

ข้อมูลอ้างอิง

Leave a Reply

Your email address will not be published.