MIRACLE LINUX dockerのインストールを行う

MIRACLE LINUX dockerのインストールを行う

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

環境

  • OS MIRACLE LINUX release 8.4 (Peony)

リポジトリ追加

まず初めに、リポジトリを追加しておきます。

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

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

$ dnf repolist

repo id                                                            repo の名前
8-latest-AppStream                                                 8-latest-AppStream
8-latest-BaseOS                                                    8-latest-BaseOS
docker-ce-stable                                                   Docker CE Stable - x86_64

dockerインストール

dnfを実行して、インストールを行います。

$ sudo dnf -y install docker-ce

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

(競合するパッケージを置き換えるには、コマンドラインに '--allowerasing' を追加してみてください または、'--skip-broken' を追加して、インストール不可のパッケージをスキップしてください または、'--nobest' を追加して、最適候補のパッケージのみを使用しないでください)

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

$ sudo dnf install docker-ce --allowerasing

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

$ docker -v

Docker version 20.10.9, build c2ea9bc

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

$ sudo systemctl enable docker
$ sudo systemctl start docker

dockerをユーザーで実行

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

$ sudo usermod -aG docker $USER

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

わざわざ、接続を抜けるのはめんどうなので、以下のコマンドを実行します。

$ 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
2db29710123e: Pull complete 
Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf
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)

fabd366cf535
7695ebf2889b

$ docker rmi $(docker images -q)

Untagged: hello-world:latest
Untagged: hello-world@sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359

docker composeインストール

docker composeもインストールしておきます。
※最新バージョンはこちらでも確認できます。

githubから最新バージョンを入手します。

$ 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 -

また、以下のように、バージョンを指定してダウンロードすることも可能です。

sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.0.1/docker-
compose-Linux-x86_64

wgetが、もしなければ以下でインストールできます。

$ sudo dnf install wget

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

$ sudo chmod +x docker-compose-linux-x86_64

バージョンを指定してダウンロードした場合は以下の場所になります
$ sudo chmod +x /usr/local/bin/docker-compose

移動させます。
※バージョンを指定してダウンロードした場合は、必要ありません。

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

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

$ docker-compose version

Docker Compose version v2.0.1