관리 메뉴

bright jazz music

[Docker] CentOS 환경에서 docker설치 본문

OS 및 기타/docker & kubernetes

[Docker] CentOS 환경에서 docker설치

bright jazz music 2023. 1. 15. 17:33

https://docs.docker.com/engine/install/centos/

 

Install Docker Engine on CentOS

 

docs.docker.com

 

- docker를 설치하기 위해선 centos 버전 7 이상이 필요

- centos-extras 리포지토리가 enabled 되어 있어야 함.

- overlay2 storage driver 사용 추천

 

1. 구버전 도커 삭제 (설치되어 있을지 모르는 것들 삭제)

 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
[root@localhost ~]# sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal

//설치된 것이 없었음

 

2. 설치 방법 선택

  • Docker's Repositories 사용 ( 가장 일반적)
  • RPM 패키지를 다운로드 받아서 수동 설치 (인터넷 연결 안되는 환경에서 주로 사용)
  • 자동화된 스크립트 사용

 

여기서는 Repository를 사용해서 가장 일반적인 설치 과정을 따를 것이다.

 

3. Repository 설정

//yum-utils패키지 설치.(yum-config-manager 제공)
sudo yum install -y yum-utils

//yum-config-manager 사용해서 repository 설정
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

 

4. docker engine 설치

//최신 버전의 engine, containerd, docker compose 설치
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

만약 GPG key를 승인하라는 메시지가 나오고, 그것이 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35와 같다면 승인할 것.

위 명령어를 실행하면 자동으로 최신 도커가 설치됨. 우리는 이 방법을 선택할 것임. 수동설치는 글 맨 뒤에 배치.

 

위 명령어를 실행하면 중간에 4개의 패키지 설치 여부를 묻는 질문이 출력된다. y 입력

 containerd.io                   x86_64       1.6.15-3.1.el7                    docker-ce-stable        33 M
 docker-ce                       x86_64       3:20.10.22-3.el7                  docker-ce-stable        22 M
 docker-ce-cli                   x86_64       1:20.10.22-3.el7                  docker-ce-stable        30 M
 docker-compose-plugin           x86_64       2.14.1-3.el7                      docker-ce-stable        10 M
 //와 그 외의 라이브러리를 다운받겠느냐는 질문이다.
 //yes
 
 /*
 =============================================================================================================
 Package                         Arch         Version                           Repository              Size
=============================================================================================================
Installing:
 containerd.io                   x86_64       1.6.15-3.1.el7                    docker-ce-stable        33 M
 docker-ce                       x86_64       3:20.10.22-3.el7                  docker-ce-stable        22 M
 docker-ce-cli                   x86_64       1:20.10.22-3.el7                  docker-ce-stable        30 M
 docker-compose-plugin           x86_64       2.14.1-3.el7                      docker-ce-stable        10 M
Installing for dependencies:
 audit-libs-python               x86_64       2.8.5-4.el7                       base                    76 k
 checkpolicy                     x86_64       2.5-8.el7                         base                   295 k
 container-selinux               noarch       2:2.119.2-1.911c772.el7_8         extras                  40 k
 docker-ce-rootless-extras       x86_64       20.10.22-3.el7                    docker-ce-stable       8.5 M
 docker-scan-plugin              x86_64       0.23.0-3.el7                      docker-ce-stable       3.8 M
 fuse-overlayfs                  x86_64       0.7.2-6.el7_8                     extras                  54 k
 fuse3-libs                      x86_64       3.6.1-4.el7                       extras                  82 k
 libcgroup                       x86_64       0.41-21.el7                       base                    66 k
 libseccomp                      x86_64       2.3.1-4.el7                       base                    56 k
 libsemanage-python              x86_64       2.5-14.el7                        base                   113 k
 policycoreutils-python          x86_64       2.5-34.el7                        base                   457 k
 python-IPy                      noarch       0.75-6.el7                        base                    32 k
 setools-libs                    x86_64       3.3.8-4.el7                       base                   620 k
 slirp4netns                     x86_64       0.4.3-4.el7_8                     extras                  81 k

Transaction Summary
=============================================================================================================
Install  4 Packages (+14 Dependent packages)

Total download size: 109 M
Installed size: 404 M
Is this ok [y/d/N]: y


 */

 

GPG key를 승인할 것인지 묻는 질문 하나 더 출력된다.

Retrieving key from https://download.docker.com/linux/centos/gpg
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를 선택한다.

//...
/*
Installed:
  containerd.io.x86_64 0:1.6.15-3.1.el7              docker-ce.x86_64 3:20.10.22-3.el7
  docker-ce-cli.x86_64 1:20.10.22-3.el7              docker-compose-plugin.x86_64 0:2.14.1-3.el7

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7                checkpolicy.x86_64 0:2.5-8.el7
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8    docker-ce-rootless-extras.x86_64 0:20.10.22-3.el7
  docker-scan-plugin.x86_64 0:0.23.0-3.el7              fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
  fuse3-libs.x86_64 0:3.6.1-4.el7                       libcgroup.x86_64 0:0.41-21.el7
  libseccomp.x86_64 0:2.3.1-4.el7                       libsemanage-python.x86_64 0:2.5-14.el7
  policycoreutils-python.x86_64 0:2.5-34.el7            python-IPy.noarch 0:0.75-6.el7
  setools-libs.x86_64 0:3.3.8-4.el7                     slirp4netns.x86_64 0:0.4.3-4.el7_8

Complete!
[root@localhost ~]#

*/

도커 설치가 완료 되었다.

 

 

5. 도커 실행

sudo systemctl start docker

 

6. 도커 정상 설치여부 확인 테스트

sudo docker run hello-world

/*
이 명령어는 test image를 다운받아서 컨테이너 안에서 실행한다.
컨테이너가 이 이미지를 실행하면 컨테이너가 메시지를 출력하고 종료된다.
*/

 

실제로 명령을 실행해 보면 아래와 같다.

[root@localhost ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe
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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

"Hello from Docker!" 메시지를 출력하기 위해서 도커는 다음의 절차를 거친다.

 

  1. Docker client가 Docker daemon에 접근한다.
  2. Docker daemon은 Docker Hub에 접근해 "hello-world"이미지를 pull한다.(다운받아 가져온다)
  3. Docker daemon은 pull한 이미지로부터 새로운 컨테이너를 생성하고 컨테이너에서 "Hello from Docker!"라는 산출물을 생성하는 executable 파일을 실행한다.
  4. Docker Daemon은 해당 산출물을 Docker Client에게 보내준다, 즉 내 터미널로 보내준다는 것이다.

 

 

 

 

 

 

* 도커 버전 선택 설치 방법

 

만약 특정 버전을 선택하여 설치하고 싶다면 아래의 명령어 실행하여 버전 확인.

yum list docker-ce --showduplicates | sort -r
//...
//docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
//docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
//docker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stable
//...
//버전 중 하나를 골라 <VERSION_STRING>에 맞는 값을 넣고 설치
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin

 

 

Comments