Rocky Linux dockerのインストール

Rocky Linux dockerのインストール

Rocky Linuxにdockerとdocker composeをインストールするまでの手順です。

環境

  • OS  Rocky Linux release 8.4 (Green Obsidian)

リポジトリ追加

まずはリポジトリを追加します。

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

追加したリポジトリを確認します。

dnf repolist

<出力結果>
repo id                                                                                repo の名前
appstream                                                                              Rocky Linux 8 - AppStream
baseos                                                                                 Rocky Linux 8 - BaseOS
docker-ce-stable                                                                       Docker CE Stable - x86_64
extras                                                                                 Rocky Linux 8 - Extras

dockerインストール

まずは、updateしておきます。

sudo dnf update

以下のコマンドを実行してインストールを行います。

sudo dnf -y install docker-ce

以下のエラーが出る場合は、

エラー: 
 問題 1: problem with installed package podman-3.0.1-7.module+el8.4.0+556+40122d08.x86_64
  - package podman-3.0.1-7.module+el8.4.0+556+40122d08.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - cannot install the best candidate for the job
  - package runc-1.0.0-65.rc10.module+el8.4.0+559+c02fa3b2.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-71.rc92.module+el8.4.0+558+7340b765.x86_64 is filtered out by modular filtering
 問題 2: problem with installed package buildah-1.19.7-2.module+el8.4.0+556+40122d08.x86_64
  - package buildah-1.19.7-2.module+el8.4.0+556+40122d08.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
  - package docker-ce-3:20.10.7-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed
  - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module+el8.4.0+556+40122d08.x86_64
  - cannot install the best candidate for the job
  - package runc-1.0.0-56.rc5.dev.git2abd837.module+el8.4.0+557+48ba8b2f.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-65.rc10.module+el8.4.0+559+c02fa3b2.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-71.rc92.module+el8.4.0+558+7340b765.x86_64 is filtered out by modular filtering
(競合するパッケージを置き換えるには、コマンドラインに '--allowerasing' を追加してみてください または、'--skip-broken' を追加して、インストール不可のパッケージをスキップしてください または、'--nobest' を追加して、最適候補のパッケージのみを使用しないでください)

「–allowerasing」をつけて、インストールします。

sudo dnf install docker-ce --allowerasing

インストールが完了したら、バージョンを確認してみます。

docker -v

<出力結果>
Docker version 20.10.7, build f0df350

起動と自動起動を設定します。

sudo systemctl enable docker
sudo systemctl start docker

dockerをユーザーで実行

dockerをユーザーで実行できるようにdockerグループに追加しておきます。

sudo usermod -aG docker ${USER}

dockerを再起動して、一度、接続を抜けてもう一度接続すれば、ユーザーで実行できます。
※別の接続を行っても同様で「su – ${USER}」を実行しても同じです。

sudo systemctl restart docker

追加していない場合は、以下のエラーが発生します。

docker info

<出力結果>
Server:
ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info: dial unix /var/run/docker.sock: connect: permission denied
errors pretty printing info

hello worldができればインストールは完了です。

docker run hello-world

<出力結果>
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
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 worldできれば2つのコマンドを実行して、削除しておきます。

docker rm $(docker ps -q -a)

<出力結果>
07e4bf45e50e

docker rmi $(docker images -q)

<出力結果>
Untagged: hello-world:latest
Untagged: hello-world@sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd

docker composeインストール

docker composeもインストールしておきます。

curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url  | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -

wgetがなければインストールします。

sudo dnf install wget

権限も設定しておきます。

sudo chmod +x docker-compose-linux-x86_64

移動させます。

sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

バージョンを確認すると、最新のバージョンである「1.29.2」がインストールされていることが確認できます。

docker-compose version

<出力結果>
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019