お金をかけずにサーバーの勉強をしよう

Dockerエンジン インストール

2025年4月11日

メニューへ戻る

Ubuntu Server 24.04に Dockerエンジンをインストールします。

Linuxのアプリケーションコンテナの世界でほぼ標準と言って良いのが Docker でしょう。

出た当初は使い所がよく分かりませんでしたが、数年を経た今では技術的なノウハウの発信もあって様々なフィールドで活用されているようです。

今やサーバーエンジニアとして押さえておくべき技術の一つとなりましたね。


1.環境

以下のセットでいきます。

Ubuntuには snap版のパッケージもありますが、最新版を使いたいので本家サイトから apt版パッケージを入手します。

Ubuntuへのインストール方法は Dockerのサイトで具体的に書かれていますので、そのままそれに従います。
2025年4月11日時点での最新バージョンは、28.0.4でした。

Ubuntu Server 24.04のインストールについては「Ubuntu 24.04 Server インストール」に書いています。

以降は Ubuntu Server が用意できたところからスタートします。


2.インストール

Ubuntuへのインストール方法はこちら。
Install Docker Engine on Ubuntu

Uninstall old versions の段落
新規インストールという前提で、この手順は割愛します。


Installation methods の段落
ここで以下の作業をします。

リポジトリデータベースを最新状態にします。

subro@UbuntuServer2404-1:~$ sudo apt-get update
ヒット:1 http://security.ubuntu.com/ubuntu noble-security InRelease
ヒット:2 http://jp.archive.ubuntu.com/ubuntu noble InRelease
ヒット:3 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease
ヒット:4 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease
パッケージリストを読み込んでいます... 完了

OSインストールしたてで既に最新状態なので特に何も起きませんでした。

HTTPSでダウンロードするための前提となるツールをインストールします。

subro@UbuntuServer2404-1:~$ sudo apt-get install ca-certificates curl
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
ca-certificates はすでに最新バージョン (20240203) です。
ca-certificates は手動でインストールしたと設定されました。
curl はすでに最新バージョン (8.5.0-2ubuntu10.6) です。
curl は手動でインストールしたと設定されました。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 1 個。

私の環境では既にインストールされていて全て最新になっていました。

HTTPSで使う公開鍵(GPG key)のダウンロードをし、
Dockerのリポジトリを参照先に追加し、
リポジトリデータベースをアップデートして Dockerのリポジトリ情報を取得します。

subro@UbuntuServer2404-1:~$ sudo install -m 0755 -d /etc/apt/keyrings

subro@UbuntuServer2404-1:~$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

subro@UbuntuServer2404-1:~$ sudo chmod a+r /etc/apt/keyrings/docker.asc

subro@UbuntuServer2404-1:~$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

subro@UbuntuServer2404-1:~$ sudo apt-get update
取得:1 https://download.docker.com/linux/ubuntu noble InRelease [48.8 kB]
取得:2 https://download.docker.com/linux/ubuntu noble/stable amd64 Packages [22.6 kB]
ヒット:3 http://jp.archive.ubuntu.com/ubuntu noble InRelease
ヒット:4 http://security.ubuntu.com/ubuntu noble-security InRelease
ヒット:5 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease
ヒット:6 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease
71.4 kB を 1秒 で取得しました (73.2 kB/s)
パッケージリストを読み込んでいます... 完了

ピンク色の行がこの作業で追加されたリポジトリです。

Dockerをインストールします。
(途中で「インストールして良いか」と聞かれるのも面倒くさいので、apt-getコマンドには -y オプションを入れました。)

subro@UbuntuServer2404-1:~$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
〜〜〜 省略 〜〜〜

特に問題なくインストールできました。

手順にある通り、テストで [hello-world]コンテナを動かしてみます。

subro@UbuntuServer2404-1:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:fc08e727181e2668370f47db6319815c279ed887e2f01be96b94106bc2781430
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]コンテナが動き出して出力したメッセージです。

上手く動いているようです。


==========
Dockerエンジンはアプリケーションコンテナの実行環境というインフラですからインストールしただけだと特に何も起きませんで、やはり何かしらのコンテナを動かしてナンボですね。

当ホームページでは Dockerコンテナで何かやっているもの(Localstackとか)もありますので、そちらもどうぞ見てやって下さい。


Dockerもほぼ出尽くし感があるのか 2025年になってから刊行されたのはこれだけみたいです。
Kubernetesも含め一時期凄く流行ったのが沈静化してしまったよう。