Ubuntu 22.04 (WSL) に Dockerをインストール

はじめに

Ubuntu 20.04 (WSL) に Dockerをインストール をベースに、Ubuntu 22.04 版としてまとめ直しました。

事前準備

systemdの有効化(WSLの場合)

systemdが有効化されていないとsystemctlを実行しても下記のようなメッセージが表示されます。

$ sudo systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

/etc/wsl.conf ファイルを新規に作成し、下記の記載を行います。

[boot]
systemd=true

設定を変更した後は、PowerShell から下記のようにWSLをシャットダウンします。

wsl --shutdown

下記が実行できることを確認します。

$ sudo systemctl

手順

$ sudo apt update
$ sudo apt install ca-certificates curl gnupg lsb-release

鍵を登録します。

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

リポジトリを登録します。

$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update

インストールします。

$ sudo apt install docker-ce

dockerグループにユーザを追加します。 (Ubuntu 22.04 Native インストール時にはこの後、OSの再起動が必要でした)

$ sudo usermod -a -G docker ${USER}

サービスが立ち上がっていることを確認します。

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-04-30 18:37:44 JST; 1min 2s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 792 (dockerd)
      Tasks: 17
     Memory: 32.7M
     CGroup: /system.slice/docker.service
             └─792 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Apr 30 18:37:43 LT1 dockerd[792]: time="2023-04-30T18:37:43.907391572+09:00" level=info msg="Loading containers: start."
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.057267860+09:00" level=info msg="Loading containers: done."
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067316328+09:00" level=warning msg="WARNING: No blkio throttle.read_bps_device support"
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067348063+09:00" level=warning msg="WARNING: No blkio throttle.write_bps_device support"
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067351293+09:00" level=warning msg="WARNING: No blkio throttle.read_iops_device support"
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067353633+09:00" level=warning msg="WARNING: No blkio throttle.write_iops_device support"
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067374922+09:00" level=info msg="Docker daemon" commit=94d3ad6 graphdriver=overlay2 version=23.0.5
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.067496800+09:00" level=info msg="Daemon has completed initialization"
Apr 30 18:37:44 LT1 systemd[1]: Started Docker Application Container Engine.
Apr 30 18:37:44 LT1 dockerd[792]: time="2023-04-30T18:37:44.082524031+09:00" level=info msg="API listen on /run/docker.sock"
Copied title and URL