Docker Engine をインストールする
Docker Engine を Linux オペレーティングシステムにインストールする方法について説明します。
はじめる前に
  • Docker Engine の詳細については、Docker の公式サイトのドキュメントを参照してください。
  • インストールを始める前に、オペレーティングシステムが前提条件を満たしているか確認してください。
以前のバージョンをアンインストールする
かつての Docker バージョンは、docker あるいは docker-engine と呼ばれていました。この Docker バージョンがインストールされている場合は、関連する依存パッケージも含めてアンインストールしてください。
Docker をアンインストールするには、以下のコマンドを入力します。
$ sudo dnf remove \
    docker \
    docker-client \
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-engine
dnf を実行したときに、上のパッケージがインストールされていないと表示されることを確認してください。 /var/lib/docker/ にはイメージ、コンテナー、ボリューム、ネットワークが含まれていて、それらは保持されたまま残ります。なお、現在の Docker Engine パッケージは、docker-ce です。
Docker 公式リポジトリーを利用したインストール
新しいホストマシンに Docker Engine を初めてインストールする場合は、事前に Docker リポジトリーをセットアップしておくことが必要です。これを行った後に、リポジトリーからの Docker のインストールやアップグレードができるようになります。
dnf-plugins-core パッケージをインストールします。このパッケージがリポジトリー管理を行うコマンドを提供します。
$ sudo dnf -y install dnf-plugins-core
Docker リポジトリーがセットアップされていないことを確認するには、以下のコマンドを入力します。
$ sudo dnf repolist | grep docker
Docker リポジトリーがセットアップされていない場合は、何も表示されません。
リポジトリーをセットアップするには、以下のコマンドを入力します。
$ sudo dnf config-manager \
    --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
再度 dnf repolist を実行することで、リポジトリーがセットアップされたことを確認できます。
$ sudo dnf repolist | grep docker
docker-ce-stable                    Docker CE Stable - x86_64
Docker Engine のインストール
  1. Docker Engine と containerd の最新版をインストールします。
    $ sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin
    これにより Docker をインストールしましたが、まだ起動はしていません。 グループ docker も生成されますが、所属するユーザーは存在していない状態です。
  2. Docker のステータスを確認します。まだ起動していないことが確認できます。
    $ sudo systemctl status docker
    ○ docker.service - Docker Application Container Engine
         Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
         Active: inactive (dead)
    TriggeredBy: ○ docker.socket
           Docs: https://docs.docker.com
  3. Docker を起動します。
    $ sudo systemctl start docker
  4. Docker のステータスを確認します。起動していることが確認できます。
    $ sudo systemctl status docker
    ● docker.service - Docker Application Container Engine
         Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
         Active: active (running) since Sat 2025-02-15 14:08:54 JST; 1min 9s ago
    TriggeredBy: ● docker.socket
           Docs: https://docs.docker.com
       Main PID: 7088 (dockerd)
          Tasks: 10
         Memory: 26.1M
            CPU: 212ms
         CGroup: /system.slice/docker.service
                 └─7088 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    
     2月 15 14:08:53 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
     2月 15 14:08:53 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:53.627141234+09:00" level=info msg="Starti>
     2月 15 14:08:53 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:53.627835251+09:00" level=info msg="OTEL t>
     2月 15 14:08:53 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:53.652639483+09:00" level=info msg="Loadin>
     2月 15 14:08:54 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:54.002298700+09:00" level=info msg="Loadin>
     2月 15 14:08:54 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:54.030132257+09:00" level=info msg="Docker>
     2月 15 14:08:54 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:54.030263745+09:00" level=info msg="Daemon>
     2月 15 14:08:54 localhost.localdomain dockerd[7088]: time="2025-02-15T14:08:54.050121048+09:00" level=info msg="API li>
     2月 15 14:08:54 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
  5. オペレーティングシステム起動時に Docker サービスの起動を有効にするには、以下のコマンドを入力します。
    $ sudo systemctl enable docker
  6. Docker サービスが有効になったことを確認します。Docker サービスが有効になっていれば enabled が表示されます。
    $ sudo systemctl is-enabled docker
非特権ユーザーが Docker コマンドを実行できるようにする
非特権ユーザーでも Docker コマンドが実行できるようにするには、docker グループにユーザーを追加します。
ログインしているユーザーを追加するには、以下のコマンドを入力します。
$ sudo usermod -aG docker $USER
Docker コマンドを使い始める前に、再ログインする必要があります。
Dockerの動作を確認する
Docker Engine が正しくインストールされていることを確認するため、hello-world イメージを実行します。 Docker グループにユーザーを追加したので、非特権ユーザーで以下のコマンドを入力して動作を確認します。
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:e0b569a5163a5e6be84e210a2587e7d447e08f87a0e90798363fa44a0464a1e8
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/
このコマンドはテスト用イメージをダウンロードし、コンテナー内で実行します。コンテナーが起動すると、上のようにメッセージを表示して終了します。
私たちは、お客さまが私たちのウェブサイトをどのように使用するのかを理解し、お客さまの体験を改善するために Cookie を使用しています。 閲覧を続けると Cookie の使用に同意したことになります。
拒否した場合、このウェブサイトにアクセスしてもお客さまの情報は追跡されません。 情報を追跡しない設定を記憶するために、ウェブブラウザで 1 つだけ Cookie が使用されます。