2025.04.23
【WSL】Dockerのインストール

JoeによるPixabayからの画像

はじめに

今回は、WSL2のUbuntu24.04にDocker(Docker Desktopではない方)をインストールします。

■ざっくりDockerとDockerDesktopの違い

【Docker】
 主にLinuxで使用するCLIツール (Windows、Macでも仮想マシン上で使用可能)

【DockerDesktop】
 主にWindows、Macで使用する、Dockerを扱いやすくしてくれるGUIツール

確認した環境

OS:Windows11 Pro/WSL2(Ubuntu24.04)

インストール手順

1)事前準備:パッケージの更新

sudo apt update sudo apt upgrade

 

2)Dockerインストール

コマンド1:Dockerのインストールに必要なツールをインストール

sudo apt install apt-transport-https ca-certificates curl software-properties-common

 

コマンド2:Docker公式のGPGキー(署名)を取得する

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

インストール元のリポジトリが安全かどうか確認するためのカギです。
信頼できる提供元からであることの証明になります。

 

コマンド3:Docker公式のリポジトリを追加する。

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

 

コマンド4:Dockerのインストール

sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io

 

3)Dockerのインストール確認

docker --version

バージョンが表示されればインストールできています。

 

4)Dockerの起動

sudo service docker start

 

5)ユーザーをDockerグループに追加  ※この手順は任意です

Dockerコマンドを実行する際に毎回「sudo」を付けたくない場合は、ユーザーを「docker」グループに追加します

sudo usermod -aG docker $USER

※変更を反映させるため、コマンド実行後WSLターミナルを再起動する

 

6)Dockerの動作確認

sudo docker run hello-world

※動作確認用のDockerイメージをダウンロードし、実行してくれます。

以下のように出力されればOKです!
初回実行時のみイメージのダウンロードを行います。

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world e6590344b1a5: Pull complete Digest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19 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:

The Docker client contacted the Docker daemon.

The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)

The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.

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/