Compute

[Kubernetes] 2.How to Install Docker

haewon83 2023. 7. 3. 15:07

 

1. OS Version 확인

# cat /etc/redhat-release
CentOS Stream release 8
 
# cat /etc/os-release
NAME="CentOS Stream"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Stream 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
 
# uname -mrn
localhost.localdomain 4.18.0-408.el8.x86_64 x86_64

 

2. 설치

## 참고 : https://docs.docker.com/engine/install/centos/

Set up the repository

# sudo yum install -y yum-utils
CentOS Stream 8 - AppStream                                                                                                                                            3.4 MB/s |  30 MB     00:08
CentOS Stream 8 - BaseOS                                                                                                                                               9.7 MB/s |  39 MB     00:03
CentOS Stream 8 - Extras                                                                                                                                                20 kB/s |  18 kB     00:00
CentOS Stream 8 - Extras common packages                                                                                                                                68  B/s | 6.6 kB     01:39
Dependencies resolved.
=======================================================================================================================================================================================================
 Package                                                    Architecture                             Version                                            Repository                                Size
=======================================================================================================================================================================================================
Installing:
 yum-utils                                                  noarch                                   4.0.21-21.el8                                      baseos                                    79 k
Upgrading:
 dnf-plugins-core                                           noarch                                   4.0.21-21.el8                                      baseos                                    76 k
 python3-dnf-plugins-core                                   noarch                                   4.0.21-21.el8                                      baseos                                   279 k
 
Transaction Summary
=======================================================================================================================================================================================================
Install  1 Package
Upgrade  2 Packages
 
Total download size: 435 k
Downloading Packages:
(1/3): dnf-plugins-core-4.0.21-21.el8.noarch.rpm                                                                                                                       125 kB/s |  76 kB     00:00
(2/3): yum-utils-4.0.21-21.el8.noarch.rpm                                                                                                                              127 kB/s |  79 kB     00:00
(3/3): python3-dnf-plugins-core-4.0.21-21.el8.noarch.rpm                                                                                                               327 kB/s | 279 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                  343 kB/s | 435 kB     00:01
CentOS Stream 8 - BaseOS                                                                                                                                               1.4 MB/s | 1.6 kB     00:00
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                               1/1
  Upgrading        : python3-dnf-plugins-core-4.0.21-21.el8.noarch                                                                                                                                 1/5
  Upgrading        : dnf-plugins-core-4.0.21-21.el8.noarch                                                                                                                                         2/5
  Installing       : yum-utils-4.0.21-21.el8.noarch                                                                                                                                                3/5
  Cleanup          : dnf-plugins-core-4.0.21-14.1.el8.noarch                                                                                                                                       4/5
  Cleanup          : python3-dnf-plugins-core-4.0.21-14.1.el8.noarch                                                                                                                               5/5
  Running scriptlet: python3-dnf-plugins-core-4.0.21-14.1.el8.noarch                                                                                                                               5/5
  Verifying        : yum-utils-4.0.21-21.el8.noarch                                                                                                                                                1/5
  Verifying        : dnf-plugins-core-4.0.21-21.el8.noarch                                                                                                                                         2/5
  Verifying        : dnf-plugins-core-4.0.21-14.1.el8.noarch                                                                                                                                       3/5
  Verifying        : python3-dnf-plugins-core-4.0.21-21.el8.noarch                                                                                                                                 4/5
  Verifying        : python3-dnf-plugins-core-4.0.21-14.1.el8.noarch                                                                                                                               5/5
 
Upgraded:
  dnf-plugins-core-4.0.21-21.el8.noarch                                                          python3-dnf-plugins-core-4.0.21-21.el8.noarch
Installed:
  yum-utils-4.0.21-21.el8.noarch
 
Complete!
 
# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

 

Install Docker Engine - To install the latest version

https://forums.docker.com/t/problem-with-installed-package-podman/116529
## 위 링크에서 기술한 오류 발생 시, 아래 링크에 따라 podman 제거 후 다시 설치 시도
https://www.ibm.com/docs/en/eam/4.2?topic=questions-troubleshooting-tips#uninstall_podman 
 
# sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Last metadata expiration check: 0:04:52 ago on Sun 18 Jun 2023 10:07:27 AM EDT.
Dependencies resolved.
=======================================================================================================================================================================================================
 Package                                            Architecture                    Version                                                            Repository                                 Size
=======================================================================================================================================================================================================
Installing:
 containerd.io                                      x86_64                          1.6.21-3.1.el8                                                     docker-ce-stable                           34 M
 docker-buildx-plugin                               x86_64                          0.10.5-1.el8                                                       docker-ce-stable                           12 M
 docker-ce                                          x86_64                          3:24.0.2-1.el8                                                     docker-ce-stable                           24 M
 docker-ce-cli                                      x86_64                          1:24.0.2-1.el8                                                     docker-ce-stable                          7.2 M
 docker-compose-plugin                              x86_64                          2.18.1-1.el8                                                       docker-ce-stable                           12 M
Installing dependencies:
 container-selinux                                  noarch                          2:2.195.1-1.module_el8.8.0+1254+78119b6e                           appstream                                  63 k
 docker-ce-rootless-extras                          x86_64                          24.0.2-1.el8                                                       docker-ce-stable                          4.9 M
 fuse-overlayfs                                     x86_64                          1.10-1.module_el8.8.0+1254+78119b6e                                appstream                                  74 k
 fuse3                                              x86_64                          3.3.0-17.el8                                                       baseos                                     54 k
 fuse3-libs                                         x86_64                          3.3.0-17.el8                                                       baseos                                     95 k
 libcgroup                                          x86_64                          0.41-19.el8                                                        baseos                                     70 k
 libslirp                                           x86_64                          4.4.0-1.module_el8.7.0+1216+b022c01d                               appstream                                  70 k
 slirp4netns                                        x86_64                          1.2.0-2.module_el8.7.0+1216+b022c01d                               appstream                                  54 k
 
Transaction Summary
=======================================================================================================================================================================================================
Install  13 Packages
 
Total download size: 94 M
Installed size: 362 M
Is this ok [y/N]: y
Downloading Packages:
(1/13): fuse-overlayfs-1.10-1.module_el8.8.0+1254+78119b6e.x86_64.rpm                                                                                                  326 kB/s |  74 kB     00:00
(2/13): libslirp-4.4.0-1.module_el8.7.0+1216+b022c01d.x86_64.rpm                                                                                                       285 kB/s |  70 kB     00:00
(3/13): container-selinux-2.195.1-1.module_el8.8.0+1254+78119b6e.noarch.rpm                                                                                            236 kB/s |  63 kB     00:00
(4/13): slirp4netns-1.2.0-2.module_el8.7.0+1216+b022c01d.x86_64.rpm                                                                                                    767 kB/s |  54 kB     00:00
(5/13): fuse3-3.3.0-17.el8.x86_64.rpm                                                                                                                                   97 kB/s |  54 kB     00:00
(6/13): libcgroup-0.41-19.el8.x86_64.rpm                                                                                                                               116 kB/s |  70 kB     00:00
(7/13): fuse3-libs-3.3.0-17.el8.x86_64.rpm                                                                                                                             140 kB/s |  95 kB     00:00
(8/13): docker-buildx-plugin-0.10.5-1.el8.x86_64.rpm                                                                                                                   4.9 MB/s |  12 MB     00:02
(9/13): docker-ce-24.0.2-1.el8.x86_64.rpm                                                                                                                              8.6 MB/s |  24 MB     00:02
(10/13): docker-ce-rootless-extras-24.0.2-1.el8.x86_64.rpm                                                                                                              16 MB/s | 4.9 MB     00:00
(11/13): docker-ce-cli-24.0.2-1.el8.x86_64.rpm                                                                                                                         9.5 MB/s | 7.2 MB     00:00
(12/13): containerd.io-1.6.21-3.1.el8.x86_64.rpm                                                                                                                       8.7 MB/s |  34 MB     00:03
(13/13): docker-compose-plugin-2.18.1-1.el8.x86_64.rpm                                                                                                                  17 MB/s |  12 MB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                   17 MB/s |  94 MB     00:05
Docker CE Stable - x86_64                                                                                                                                              7.7 kB/s | 1.6 kB     00:00
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       :https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                               1/1
  Installing       : docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                                                                    1/13
  Running scriptlet: docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                                                                    1/13
  Installing       : fuse3-libs-3.3.0-17.el8.x86_64                                                                                                                                               2/13
  Running scriptlet: fuse3-libs-3.3.0-17.el8.x86_64                                                                                                                                               2/13
  Running scriptlet: container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch                                                                                                            3/13
  Installing       : container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch                                                                                                            3/13
  Running scriptlet: container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch                                                                                                            3/13
  Installing       : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                          4/13
  Running scriptlet: containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                          4/13
  Installing       : fuse3-3.3.0-17.el8.x86_64                                                                                                                                                    5/13
  Installing       : fuse-overlayfs-1.10-1.module_el8.8.0+1254+78119b6e.x86_64                                                                                                                    6/13
  Running scriptlet: fuse-overlayfs-1.10-1.module_el8.8.0+1254+78119b6e.x86_64                                                                                                                    6/13
  Installing       : docker-buildx-plugin-0.10.5-1.el8.x86_64                                                                                                                                     7/13
  Running scriptlet: docker-buildx-plugin-0.10.5-1.el8.x86_64                                                                                                                                     7/13
  Installing       : docker-ce-cli-1:24.0.2-1.el8.x86_64                                                                                                                                          8/13
  Running scriptlet: docker-ce-cli-1:24.0.2-1.el8.x86_64                                                                                                                                          8/13
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                                 9/13
  Installing       : libcgroup-0.41-19.el8.x86_64                                                                                                                                                 9/13
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                                 9/13
  Installing       : libslirp-4.4.0-1.module_el8.7.0+1216+b022c01d.x86_64                                                                                                                        10/13
  Installing       : slirp4netns-1.2.0-2.module_el8.7.0+1216+b022c01d.x86_64                                                                                                                     11/13
  Installing       : docker-ce-rootless-extras-24.0.2-1.el8.x86_64                                                                                                                               12/13
  Running scriptlet: docker-ce-rootless-extras-24.0.2-1.el8.x86_64                                                                                                                               12/13
  Installing       : docker-ce-3:24.0.2-1.el8.x86_64                                                                                                                                             13/13
  Running scriptlet: docker-ce-3:24.0.2-1.el8.x86_64                                                                                                                                             13/13
  Running scriptlet: container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch                                                                                                           13/13
  Running scriptlet: docker-ce-3:24.0.2-1.el8.x86_64                                                                                                                                             13/13
  Verifying        : container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch                                                                                                            1/13
  Verifying        : fuse-overlayfs-1.10-1.module_el8.8.0+1254+78119b6e.x86_64                                                                                                                    2/13
  Verifying        : libslirp-4.4.0-1.module_el8.7.0+1216+b022c01d.x86_64                                                                                                                         3/13
  Verifying        : slirp4netns-1.2.0-2.module_el8.7.0+1216+b022c01d.x86_64                                                                                                                      4/13
  Verifying        : fuse3-3.3.0-17.el8.x86_64                                                                                                                                                    5/13
  Verifying        : fuse3-libs-3.3.0-17.el8.x86_64                                                                                                                                               6/13
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                                                                                                                 7/13
  Verifying        : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                          8/13
  Verifying        : docker-buildx-plugin-0.10.5-1.el8.x86_64                                                                                                                                     9/13
  Verifying        : docker-ce-3:24.0.2-1.el8.x86_64                                                                                                                                             10/13
  Verifying        : docker-ce-cli-1:24.0.2-1.el8.x86_64                                                                                                                                         11/13
  Verifying        : docker-ce-rootless-extras-24.0.2-1.el8.x86_64                                                                                                                               12/13
  Verifying        : docker-compose-plugin-2.18.1-1.el8.x86_64                                                                                                                                   13/13
 
Installed:
  container-selinux-2:2.195.1-1.module_el8.8.0+1254+78119b6e.noarch        containerd.io-1.6.21-3.1.el8.x86_64                              docker-buildx-plugin-0.10.5-1.el8.x86_64
  docker-ce-3:24.0.2-1.el8.x86_64                                          docker-ce-cli-1:24.0.2-1.el8.x86_64                              docker-ce-rootless-extras-24.0.2-1.el8.x86_64
  docker-compose-plugin-2.18.1-1.el8.x86_64                                fuse-overlayfs-1.10-1.module_el8.8.0+1254+78119b6e.x86_64        fuse3-3.3.0-17.el8.x86_64
  fuse3-libs-3.3.0-17.el8.x86_64                                           libcgroup-0.41-19.el8.x86_64                                     libslirp-4.4.0-1.module_el8.7.0+1216+b022c01d.x86_64
  slirp4netns-1.2.0-2.module_el8.7.0+1216+b022c01d.x86_64
 
Complete!

 

Start Docker

# sudo systemctl enable docker
# sudo systemctl start docker

 

Verify that the Docker Engine installation is successful by running the hello-world image

# sudo docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:c2e23624975516c7e27b1b25be3682a8c6c4c0cea011b791ce98aa423b5040a0
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest
 
# sudo 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.
    (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://hub.docker.com/
 
For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

Docker 버전 확인

# sudo docker version
Client: Docker Engine - Community
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:53:10 2023
 OS/Arch:           linux/amd64
 Context:           default
 
Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:10 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

 

후속 작업

## 방화벽 Off
# sudo systemctl stop firewalld && sudo systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
 
## SELinux 비활성화
# sudo setenforce 0
# sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# reboot
 
## Swap off
# sudo swapoff -a
# sudo sed -i -e '/swap/d' /etc/fstab
 
## hosts 파일 수정
###.###.###.###  master01 master01.k8s
###.###.###.###  worker01 worker01.k8s
###.###.###.###  worker02 worker02.k8s
###.###.###.###  worker03 worker03.k8s