CentOS8에 Docker를 설치하는 방법

CentOS8에 Docker를 설치하는 방법

2022-10-05 last update

12 minutes reading 설치 centos8 도커
CentOS8에 Docker를 설치했으므로 그 단계를 소개합니다.

1. 환경


  • OS: CentOS Linux release 8.5.2111
  • [[email protected] ~]# cat /etc/redhat-release
    CentOS Linux release 8.5.2111
    [[email protected] ~]#
    

    2. 설치 절차


    다음 명령을 사용하여 Docker 리포지토리 URL을 추가합니다.dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    실행 결과
    [[email protected] ~]# dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    repo の追加: https://download.docker.com/linux/centos/docker-ce.repo
    [[email protected] ~]#
    

     
    다음 명령을 사용하여 docker-ce, docker-ce-cli 및 containerd.io를 설치합니다.dnf install -y docker-ce docker-ce-cli containerd.io실행 결과

    실행 결과
    [[email protected] ~]# dnf install -y docker-ce docker-ce-cli containerd.io
    メタデータの期限切れの最終確認: 0:23:39 時間前の 2022年03月24日 20時36分19秒 に 実施しました。
    依存関係が解決しました。
    ================================================================================
     パッケージ                Arch   バージョン             リポジトリー     サイズ
    ================================================================================
    インストール:
     containerd.io             x86_64 1.5.11-3.1.el8         docker-ce-stable  29 M
     docker-ce                 x86_64 3:20.10.14-3.el8       docker-ce-stable  22 M
     docker-ce-cli             x86_64 1:20.10.14-3.el8       docker-ce-stable  30 M
    依存関係のインストール:
     container-selinux         noarch 2:2.167.0-1.module_el8.5.0+911+f19012f9
                                                             appstream         54 k
     docker-ce-rootless-extras x86_64 20.10.14-3.el8         docker-ce-stable 4.6 M
     docker-scan-plugin        x86_64 0.17.0-3.el8           docker-ce-stable 3.8 M
     fuse-overlayfs            x86_64 1.7.1-1.module_el8.5.0+890+6b136101
                                                             appstream         73 k
     fuse3                     x86_64 3.2.1-12.el8           baseos            50 k
     fuse3-libs                x86_64 3.2.1-12.el8           baseos            94 k
     libcgroup                 x86_64 0.41-19.el8            baseos            70 k
     libslirp                  x86_64 4.4.0-1.module_el8.5.0+890+6b136101
                                                             appstream         70 k
     slirp4netns               x86_64 1.1.8-1.module_el8.5.0+890+6b136101
                                                             appstream         51 k
    
    トランザクションの概要
    ================================================================================
    インストール  12 パッケージ
    
    ダウンロードサイズの合計: 90 M
    インストール後のサイズ: 374 M
    パッケージのダウンロード:
    (1/12): libslirp-4.4.0-1.module_el8.5.0+890+6b1 724 kB/s |  70 kB     00:00
    (2/12): container-selinux-2.167.0-1.module_el8. 532 kB/s |  54 kB     00:00
    (3/12): fuse-overlayfs-1.7.1-1.module_el8.5.0+8 698 kB/s |  73 kB     00:00
    (4/12): slirp4netns-1.1.8-1.module_el8.5.0+890+ 3.1 MB/s |  51 kB     00:00
    (5/12): fuse3-3.2.1-12.el8.x86_64.rpm           2.5 MB/s |  50 kB     00:00
    (6/12): libcgroup-0.41-19.el8.x86_64.rpm        3.6 MB/s |  70 kB     00:00
    (7/12): fuse3-libs-3.2.1-12.el8.x86_64.rpm      2.9 MB/s |  94 kB     00:00
    (8/12): docker-ce-20.10.14-3.el8.x86_64.rpm      11 MB/s |  22 MB     00:01
    (9/12): docker-ce-rootless-extras-20.10.14-3.el 8.6 MB/s | 4.6 MB     00:00
    (10/12): docker-ce-cli-20.10.14-3.el8.x86_64.rp 7.8 MB/s |  30 MB     00:03
    (11/12): docker-scan-plugin-0.17.0-3.el8.x86_64 2.3 MB/s | 3.8 MB     00:01
    (12/12): containerd.io-1.5.11-3.1.el8.x86_64.rp 5.8 MB/s |  29 MB     00:04
    --------------------------------------------------------------------------------
    合計                                             18 MB/s |  90 MB     00:05
    トランザクションの確認を実行中
    トランザクションの確認に成功しました。
    トランザクションのテストを実行中
    トランザクションのテストに成功しました。
    トランザクションを実行中
      準備             :                                                        1/1
      インストール中   : docker-scan-plugin-0.17.0-3.el8.x86_64                1/12
      scriptletの実行中: docker-scan-plugin-0.17.0-3.el8.x86_64                1/12
      インストール中   : docker-ce-cli-1:20.10.14-3.el8.x86_64                 2/12
      scriptletの実行中: docker-ce-cli-1:20.10.14-3.el8.x86_64                 2/12
      scriptletの実行中: container-selinux-2:2.167.0-1.module_el8.5.0+911+f    3/12
      インストール中   : container-selinux-2:2.167.0-1.module_el8.5.0+911+f    3/12
      scriptletの実行中: container-selinux-2:2.167.0-1.module_el8.5.0+911+f    3/12
      インストール中   : containerd.io-1.5.11-3.1.el8.x86_64                   4/12
      scriptletの実行中: containerd.io-1.5.11-3.1.el8.x86_64                   4/12
      scriptletの実行中: libcgroup-0.41-19.el8.x86_64                          5/12
      インストール中   : libcgroup-0.41-19.el8.x86_64                          5/12
      scriptletの実行中: libcgroup-0.41-19.el8.x86_64                          5/12
      インストール中   : fuse3-libs-3.2.1-12.el8.x86_64                        6/12
      scriptletの実行中: fuse3-libs-3.2.1-12.el8.x86_64                        6/12
      インストール中   : fuse3-3.2.1-12.el8.x86_64                             7/12
      インストール中   : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101    8/12
      scriptletの実行中: fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101    8/12
      インストール中   : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_6    9/12
      インストール中   : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x8   10/12
      インストール中   : docker-ce-rootless-extras-20.10.14-3.el8.x86_64      11/12
      scriptletの実行中: docker-ce-rootless-extras-20.10.14-3.el8.x86_64      11/12
      インストール中   : docker-ce-3:20.10.14-3.el8.x86_64                    12/12
      scriptletの実行中: docker-ce-3:20.10.14-3.el8.x86_64                    12/12
      scriptletの実行中: container-selinux-2:2.167.0-1.module_el8.5.0+911+f   12/12
      scriptletの実行中: docker-ce-3:20.10.14-3.el8.x86_64                    12/12
      検証             : container-selinux-2:2.167.0-1.module_el8.5.0+911+f    1/12
      検証             : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101    2/12
      検証             : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_6    3/12
      検証             : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x8    4/12
      検証             : fuse3-3.2.1-12.el8.x86_64                             5/12
      検証             : fuse3-libs-3.2.1-12.el8.x86_64                        6/12
      検証             : libcgroup-0.41-19.el8.x86_64                          7/12
      検証             : containerd.io-1.5.11-3.1.el8.x86_64                   8/12
      検証             : docker-ce-3:20.10.14-3.el8.x86_64                     9/12
      検証             : docker-ce-cli-1:20.10.14-3.el8.x86_64                10/12
      検証             : docker-ce-rootless-extras-20.10.14-3.el8.x86_64      11/12
      検証             : docker-scan-plugin-0.17.0-3.el8.x86_64               12/12
    
    インストール済み:
      container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch
      containerd.io-1.5.11-3.1.el8.x86_64
      docker-ce-3:20.10.14-3.el8.x86_64
      docker-ce-cli-1:20.10.14-3.el8.x86_64
      docker-ce-rootless-extras-20.10.14-3.el8.x86_64
      docker-scan-plugin-0.17.0-3.el8.x86_64
      fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64
      fuse3-3.2.1-12.el8.x86_64
      fuse3-libs-3.2.1-12.el8.x86_64
      libcgroup-0.41-19.el8.x86_64
      libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64
      slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64
    
    完了しました!
    [[email protected] ~]#
    

     docker -v 명령으로 설치된 Docker 버전을 확인합니다.

    실행 결과
    [[email protected] ~]# docker -v
    Docker version 20.10.14, build a224086
    [[email protected] ~]#
    

    3. Docker 시작, 중지

    systemctl 명령으로 시작 및 중지합니다.

    3.1. 시작

    systemctl start docker
    실행 결과
    [[email protected] ~]# systemctl start docker
    [[email protected] ~]#
    

    3.2. 정지

    systemctl stop docker.socketsystemctl stop docker
    실행 결과
    [[email protected] ~]# systemctl stop docker.socket
    [[email protected] ~]# systemctl stop docker
    [[email protected] ~]#
    

    3.3. 자동 시작 활성화

    systemctl enable docker
    실행 결과
    [[email protected] ~]# systemctl enable docker
    Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
    [[email protected] ~]#
    

    4. 동작 확인


    여기에서는 동작 확인을 위해 공식 hello-world 컨테이너를 실행합니다.
    다음 명령을 사용하여 Docker를 시작합니다.systemctl start docker
    실행 결과
    [[email protected] ~]# systemctl start docker
    [[email protected] ~]#
    

     
    다음 명령을 사용하여 hello-world 컨테이너를 시작합니다.docker run hello-world
    실행 결과
    [[email protected] ~]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    2db29710123e: Pull complete
    Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
    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/
    
    [[email protected] ~]#
    

    hello-world 컨테이너 시작이 확인되었습니다.
     
    다음 명령을 사용하여 현재 Docker 이미지를 확인합니다.docker images
    실행 결과
    [[email protected] ~]# docker images
    REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
    hello-world   latest    feb5d9fea6a5   6 months ago   13.3kB
    [[email protected] ~]#
    

     
    다음 명령으로 Docker 컨테이너를 확인합니다.docker ps -a( -a 옵션을 넣지 않으면 시작중인 컨테이너 만 표시됩니다.)

    실행 결과
    [[email protected] ~]# docker ps -a
    CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
    f12d5082cdb2   hello-world   "/hello"   6 minutes ago   Exited (0) 6 minutes ago             gallant_leavitt
    [[email protected] ~]#
    

    STATUS 가 Exited (0) 6 minutes ago 는 이유는 hello-world 컨테이너가 메시지 출력이 끝나면 컨테이너를 중지하기 때문입니다.
     
    hello-world 컨테이너는 이후 사용하지 않으므로 다음 명령으로 컨테이너를 삭제합니다.docker rm <CONTAINER ID>
    실행 결과
    [[email protected] ~]# docker rm f12d5082cdb2
    f12d5082cdb2
    [[email protected] ~]#
    

     
    다음 명령을 사용하여 hello-world 이미지를 삭제합니다.docker rmi hello-world
    실행 결과
    [[email protected] ~]# docker rmi hello-world
    Untagged: hello-world:latest
    Untagged: [email protected]:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
    Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
    Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
    [[email protected] ~]#
    

    참고


    토호호의 도커 입문 - 토호호의 WWW 입문

    이상