Cài đặt Docker trên Ubuntu 18.04

Cài đặt Docker trên Ubuntu 18.04 Cuongquach.comDocker là một open platform cung cấp cho lập trình viên sử dụng những công cụ, service để người sử dụng có thể đóng gói và chạy chương trình của mình trên các môi trường khác nhau một cách nhanh nhất.

Chúng ta sẽ cùng tìm hiểu bước đầu tiên cơ bản khi tiếp cận và làm quen hệ thống Docker . Đó chính là tìm hiểu cách thức để cài đặt dịch vụ Docker trên máy chủ Linux như Ubuntu 18.04.cai-dat-docker-ubuntu-1804

Docker CE là gì ?

Bài viết này chúng ta sẽ không tìm hiểu Docker là gì ? Nội dung về công nghệ này ra sao. Mà chỉ tập trung vào việc cài đặt công nghệ dịch vụ Docker trên máy chủ Linux.

Hiện tại Docker chia làm 2 phiên bản : Docker Community Edition (CE) và Docker EE (Enterprise Edition). Và phiên bản miễn phí mã nguồn mở chúng ta sẽ sử dụng chính là Docker CE.

Gói chương trình Docker Community Edition hiện tại tính đến tháng 06/2018 có tên gọi là ‘docker-ce’ nên bạn sẽ thấy khác với các tên gói chương trình Docker phiên bản cũ khi cài đặt trên máy chủ Ubuntu hay CentOS.

Video hướng dẫn cài đặt Docker trên Ubuntu 18.04

Thao tác cài đặt Docker CE trên Ubuntu 18.04

Kiểm tra phiên bản Ubuntu nào.

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

Cài đặt một số chương trình hỗ trợ.

# sudo apt update
# sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y

Xoá các phiên bản Docker cũ nếu có.

# apt-get remove docker docker-engine docker.io containerd runc

Thêm thông tin Docker GPG Key chính chủ vào hệ thống.

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

Giờ ta thêm thông tin Docker Repository.

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

Tiến hành cài đặt Docker trên Ubuntu 18.04.

# sudo apt install docker-ce docker-ce-cli -y

Khởi động dịch vụ Docker và cấu hình để Docker luôn khởi động cùng máy chủ.

# systemctl start docker
# systemctl enable docker

Kiểm tra trạng thái dịch vụ Docker trên Ubuntu 18.04 nào.

# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-05-12 10:26:54 UTC; 32s ago
     Docs: https://docs.docker.com
 Main PID: 3453 (dockerd)
    Tasks: 10
   CGroup: /system.slice/docker.service
           └─3453 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.524701484Z" level=warning msg="Your kernel does not support swap memory limit"
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.524728904Z" level=warning msg="Your kernel does not support cgroup rt period"
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.524737766Z" level=warning msg="Your kernel does not support cgroup rt runtime"
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.524926405Z" level=info msg="Loading containers: start."
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.750201530Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.925721470Z" level=info msg="Loading containers: done."
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.971221784Z" level=info msg="Docker daemon" commit=afacb8b7f0 graphdriver(s)=overlay2 version=19.03.8
May 12 10:26:53 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:53.971339430Z" level=info msg="Daemon has completed initialization"
May 12 10:26:54 ip-172-31-32-36 dockerd[3453]: time="2020-05-12T10:26:54.000850063Z" level=info msg="API listen on /var/run/docker.sock"
May 12 10:26:54 ip-172-31-32-36 systemd[1]: Started Docker Application Container Engine.

Kiểm tra thông tin về dịch vụ Docker.

# docker info
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.8
 Storage Driver: overlay2
  Backing Filesystem: <unknown>
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-1065-aws
 Operating System: Ubuntu 18.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.794GiB
 Name: ip-172-31-32-36
 ID: 6TKF:P6RK:R45D:WDM4:A755:PM56:LAYD:LATU:3QPZ:Z6ML:VMJI:TA4B
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Pull thử một Docker Image đơn giản.

# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
54fec2fa59d0: Pull complete
4ede6f09aefe: Pull complete
f9dc69acb465: Pull complete
Digest: sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 602e111c06b6 2 weeks ago 127MB

Vậy là bạn đã biết cách cài đặt dịch vụ Docker trên hệ điều hành Ubuntu 18.04 rồi nhé.

Nguồn: https://cuongquach.com/

Previous articleTìm hiểu về AWS Versioning IAM Policy
Next articleEbook Kubernetes Up and Running 2nd Edition (PDF)
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !