Docker:WSL上にDocker環境を構築する方法


WSL上にDocker環境を構築する方法

WSL上にDocker環境を構築したいが、1コマンドで完了、という訳にはいかないっぽいので手順をメモ

環境

Windows 11 Home 25H2 (26200.8037)
WSL:
PS C:\Users\xxx> wsl --version
WSL バージョン: 2.6.3.0
カーネル バージョン: 6.6.87.2-1
WSLg バージョン: 1.0.71
MSRDC バージョン: 1.2.6353
Direct3D バージョン: 1.611.1-81528511
DXCore バージョン: 10.0.26100.1-240331-1435.ge-release
Windows バージョン: 10.0.26200.8037
Ubuntu:
xxx@hppc:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.4 LTS
Release: 24.04
Codename: noble

手順

1. Dockerの前提パッケージのインストール
sudo apt install -y apt-transport-https ca-certificates gnupg-agent software-properties-common
実行結果:
xxx@hppc:~$ sudo apt install -y apt-transport-https ca-certificates gnupg-agent software-properties-common
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
ca-certificates はすでに最新バージョン (20240203) です。
ca-certificates は手動でインストールしたと設定されました。
software-properties-common はすでに最新バージョン (0.99.49.4) です。
software-properties-common は手動でインストールしたと設定されました。
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libdrm-nouveau2 libdrm-radeon1 libgl1-amber-dri libglapi-mesa libllvm17t64 libwayland-server0
  libxcb-dri2-0
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージが新たにインストールされます:
  apt-transport-https gnupg-agent
アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 2 個。
8,642 B のアーカイブを取得する必要があります。
この操作後に追加で 64.5 kB のディスク容量が消費されます。
取得:1 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 apt-transport-https all 2.8.3 [3,970 B]
取得:2 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 gnupg-agent all 2.4.4-2ubuntu17.4 [4,672 B]
8,642 B を 1秒 で取得しました (8,212 B/s)
以前に未選択のパッケージ apt-transport-https を選択しています。
(データベースを読み込んでいます ... 現在 46859 個のファイルとディレクトリがインストールされています。)
.../apt-transport-https_2.8.3_all.deb を展開する準備をしています ...
apt-transport-https (2.8.3) を展開しています...
以前に未選択のパッケージ gnupg-agent を選択しています。
.../gnupg-agent_2.4.4-2ubuntu17.4_all.deb を展開する準備をしています ...
gnupg-agent (2.4.4-2ubuntu17.4) を展開しています...
apt-transport-https (2.8.3) を設定しています ...
gnupg-agent (2.4.4-2ubuntu17.4) を設定しています ...      
    

2. DockerのGPGキーの取得とリポジトリの追加
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
実行結果:
xxx@hppc:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
Repository: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu noble stable'
Description:
Archive for codename: noble components: stable
More info: https://download.docker.com/linux/ubuntu
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-noble.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-noble.list
取得:1 https://download.docker.com/linux/ubuntu noble InRelease [48.5 kB]
ヒット:2 http://archive.ubuntu.com/ubuntu noble InRelease
取得:3 https://download.docker.com/linux/ubuntu noble/stable amd64 Packages [46.7 kB]
ヒット:4 http://archive.ubuntu.com/ubuntu noble-updates InRelease
ヒット:5 http://security.ubuntu.com/ubuntu noble-security InRelease
ヒット:6 http://archive.ubuntu.com/ubuntu noble-backports InRelease
95.2 kB を 1秒 で取得しました (97.7 kB/s)
パッケージリストを読み込んでいます... 完了
W: https://download.docker.com/linux/ubuntu/dists/noble/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
    

3. Docker本体のインストールとdocker-composeのインストール
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo apt install docker-compose
実行結果:
xxx@hppc:~$ sudo apt install -y docker-ce docker-ce-cli containerd.io
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libdrm-nouveau2 libdrm-radeon1 libgl1-amber-dri libglapi-mesa libllvm17t64 libwayland-server0
  libxcb-dri2-0
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  docker-buildx-plugin docker-ce-rootless-extras docker-compose-plugin iptables libip4tc2 libip6tc2
  libslirp0 pigz slirp4netns
提案パッケージ:
  cgroupfs-mount | cgroup-lite docker-model-plugin firewalld
以下のパッケージが新たにインストールされます:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras
  docker-compose-plugin iptables libip4tc2 libip6tc2 libslirp0 pigz slirp4netns
アップグレード: 0 個、新規インストール: 12 個、削除: 0 個、保留: 2 個。
97.6 MB のアーカイブを取得する必要があります。
この操作後に追加で 395 MB のディスク容量が消費されます。
取得:1 https://download.docker.com/linux/ubuntu noble/stable amd64 containerd.io amd64 2.2.2-1~ubuntu.24.04~noble [23.6 MB]
取得:2 http://archive.ubuntu.com/ubuntu noble/main amd64 libip4tc2 amd64 1.8.10-3ubuntu2 [23.3 kB]
取得:3 https://download.docker.com/linux/ubuntu noble/stable amd64 docker-ce-cli amd64 5:29.3.0-1~ubuntu.24.04~noble [16.4 MB]
取得:4 http://archive.ubuntu.com/ubuntu noble/main amd64 libip6tc2 amd64 1.8.10-3ubuntu2 [23.7 kB]
取得:5 http://archive.ubuntu.com/ubuntu noble/main amd64 iptables amd64 1.8.10-3ubuntu2 [381 kB]
取得:6 https://download.docker.com/linux/ubuntu noble/stable amd64 docker-ce amd64 5:29.3.0-1~ubuntu.24.04~noble [22.6 MB]
取得:7 https://download.docker.com/linux/ubuntu noble/stable amd64 docker-buildx-plugin amd64 0.31.1-1~ubuntu.24.04~noble [20.3 MB]
取得:8 http://archive.ubuntu.com/ubuntu noble/universe amd64 pigz amd64 2.8-1 [65.6 kB]
取得:9 http://archive.ubuntu.com/ubuntu noble/main amd64 libslirp0 amd64 4.7.0-1ubuntu3 [63.8 kB]
取得:10 http://archive.ubuntu.com/ubuntu noble/universe amd64 slirp4netns amd64 1.2.1-1build2 [34.9 kB]
取得:11 https://download.docker.com/linux/ubuntu noble/stable amd64 docker-ce-rootless-extras amd64 5:29.3.0-1~ubuntu.24.04~noble [6,390 kB]
取得:12 https://download.docker.com/linux/ubuntu noble/stable amd64 docker-compose-plugin amd64 5.1.0-1~ubuntu.24.04~noble [7,847 kB]
97.6 MB を 4秒 で取得しました (24.2 MB/s)
以前に未選択のパッケージ containerd.io を選択しています。
(データベースを読み込んでいます ... 現在 46867 個のファイルとディレクトリがインストールされています。)
.../00-containerd.io_2.2.2-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
containerd.io (2.2.2-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ docker-ce-cli を選択しています。
.../01-docker-ce-cli_5%3a29.3.0-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
docker-ce-cli (5:29.3.0-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ libip4tc2:amd64 を選択しています。
.../02-libip4tc2_1.8.10-3ubuntu2_amd64.deb を展開する準備をしています ...
libip4tc2:amd64 (1.8.10-3ubuntu2) を展開しています...
以前に未選択のパッケージ libip6tc2:amd64 を選択しています。
.../03-libip6tc2_1.8.10-3ubuntu2_amd64.deb を展開する準備をしています ...
libip6tc2:amd64 (1.8.10-3ubuntu2) を展開しています...
以前に未選択のパッケージ iptables を選択しています。
.../04-iptables_1.8.10-3ubuntu2_amd64.deb を展開する準備をしています ...
iptables (1.8.10-3ubuntu2) を展開しています...
以前に未選択のパッケージ docker-ce を選択しています。
.../05-docker-ce_5%3a29.3.0-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
docker-ce (5:29.3.0-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ pigz を選択しています。
.../06-pigz_2.8-1_amd64.deb を展開する準備をしています ...
pigz (2.8-1) を展開しています...
以前に未選択のパッケージ docker-buildx-plugin を選択しています。
.../07-docker-buildx-plugin_0.31.1-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
docker-buildx-plugin (0.31.1-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ docker-ce-rootless-extras を選択しています。
.../08-docker-ce-rootless-extras_5%3a29.3.0-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
docker-ce-rootless-extras (5:29.3.0-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ docker-compose-plugin を選択しています。
.../09-docker-compose-plugin_5.1.0-1~ubuntu.24.04~noble_amd64.deb を展開する準備をしています ...
docker-compose-plugin (5.1.0-1~ubuntu.24.04~noble) を展開しています...
以前に未選択のパッケージ libslirp0:amd64 を選択しています。
.../10-libslirp0_4.7.0-1ubuntu3_amd64.deb を展開する準備をしています ...
libslirp0:amd64 (4.7.0-1ubuntu3) を展開しています...
以前に未選択のパッケージ slirp4netns を選択しています。
.../11-slirp4netns_1.2.1-1build2_amd64.deb を展開する準備をしています ...
slirp4netns (1.2.1-1build2) を展開しています...
libip4tc2:amd64 (1.8.10-3ubuntu2) を設定しています ...
libip6tc2:amd64 (1.8.10-3ubuntu2) を設定しています ...
docker-buildx-plugin (0.31.1-1~ubuntu.24.04~noble) を設定しています ...
containerd.io (2.2.2-1~ubuntu.24.04~noble) を設定しています ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /usr/lib/systemd/system/containerd.service.
docker-compose-plugin (5.1.0-1~ubuntu.24.04~noble) を設定しています ...
docker-ce-cli (5:29.3.0-1~ubuntu.24.04~noble) を設定しています ...
libslirp0:amd64 (4.7.0-1ubuntu3) を設定しています ...
pigz (2.8-1) を設定しています ...
docker-ce-rootless-extras (5:29.3.0-1~ubuntu.24.04~noble) を設定しています ...
slirp4netns (1.2.1-1build2) を設定しています ...
iptables (1.8.10-3ubuntu2) を設定しています ...
update-alternatives: /usr/sbin/iptables (iptables) を提供するために自動モードで /usr/sbin/iptables-legacy を使います
update-alternatives: /usr/sbin/ip6tables (ip6tables) を提供するために自動モードで /usr/sbin/ip6tables-legacy を使います
update-alternatives: /usr/sbin/iptables (iptables) を提供するために自動モードで /usr/sbin/iptables-nft を使います
update-alternatives: /usr/sbin/ip6tables (ip6tables) を提供するために自動モードで /usr/sbin/ip6tables-nft を使います
update-alternatives: /usr/sbin/arptables (arptables) を提供するために自動モードで /usr/sbin/arptables-nft を使います
update-alternatives: /usr/sbin/ebtables (ebtables) を提供するために自動モードで /usr/sbin/ebtables-nft を使います
docker-ce (5:29.3.0-1~ubuntu.24.04~noble) を設定しています ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /usr/lib/systemd/system/docker.socket.
man-db (2.12.0-4build2) のトリガを処理しています ...
libc-bin (2.39-0ubuntu8.7) のトリガを処理しています ...
xxx@hppc:~$ sudo apt install docker-compose
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libdrm-nouveau2 libdrm-radeon1 libgl1-amber-dri libglapi-mesa libllvm17t64 libwayland-server0
  libxcb-dri2-0
これを削除するには 'sudo apt autoremove' を利用してください。
以下の追加パッケージがインストールされます:
  python3-compose python3-docker python3-dockerpty python3-docopt python3-dotenv python3-packaging
  python3-texttable python3-websocket
推奨パッケージ:
  docker.io
以下のパッケージが新たにインストールされます:
  docker-compose python3-compose python3-docker python3-dockerpty python3-docopt python3-dotenv
  python3-packaging python3-texttable python3-websocket
アップグレード: 0 個、新規インストール: 9 個、削除: 0 個、保留: 2 個。
338 kB のアーカイブを取得する必要があります。
この操作後に追加で 1,779 kB のディスク容量が消費されます。
続行しますか? [Y/n] y
取得:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-websocket all 1.7.0-1 [38.1 kB]
取得:2 http://archive.ubuntu.com/ubuntu noble/main amd64 python3-packaging all 24.0-1 [41.1 kB]
取得:3 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 python3-docker all 5.0.3-1ubuntu1.1 [89.1 kB]
取得:4 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-dockerpty all 0.4.1-5 [11.4 kB]
取得:5 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-docopt all 0.6.2-6 [26.1 kB]
取得:6 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-dotenv all 1.0.1-1 [22.3 kB]
取得:7 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-texttable all 1.6.7-1 [11.0 kB]
取得:8 http://archive.ubuntu.com/ubuntu noble/universe amd64 python3-compose all 1.29.2-6ubuntu1 [84.6 kB]
取得:9 http://archive.ubuntu.com/ubuntu noble/universe amd64 docker-compose all 1.29.2-6ubuntu1 [14.0 kB]
338 kB を 2秒 で取得しました (168 kB/s)
以前に未選択のパッケージ python3-websocket を選択しています。
(データベースを読み込んでいます ... 現在 47330 個のファイルとディレクトリがインストールされています。)
.../0-python3-websocket_1.7.0-1_all.deb を展開する準備をしています ...
python3-websocket (1.7.0-1) を展開しています...
以前に未選択のパッケージ python3-packaging を選択しています。
.../1-python3-packaging_24.0-1_all.deb を展開する準備をしています ...
python3-packaging (24.0-1) を展開しています...
以前に未選択のパッケージ python3-docker を選択しています。
.../2-python3-docker_5.0.3-1ubuntu1.1_all.deb を展開する準備をしています ...
python3-docker (5.0.3-1ubuntu1.1) を展開しています...
以前に未選択のパッケージ python3-dockerpty を選択しています。
.../3-python3-dockerpty_0.4.1-5_all.deb を展開する準備をしています ...
python3-dockerpty (0.4.1-5) を展開しています...
以前に未選択のパッケージ python3-docopt を選択しています。
.../4-python3-docopt_0.6.2-6_all.deb を展開する準備をしています ...
python3-docopt (0.6.2-6) を展開しています...
以前に未選択のパッケージ python3-dotenv を選択しています。
.../5-python3-dotenv_1.0.1-1_all.deb を展開する準備をしています ...
python3-dotenv (1.0.1-1) を展開しています...
以前に未選択のパッケージ python3-texttable を選択しています。
.../6-python3-texttable_1.6.7-1_all.deb を展開する準備をしています ...
python3-texttable (1.6.7-1) を展開しています...
以前に未選択のパッケージ python3-compose を選択しています。
.../7-python3-compose_1.29.2-6ubuntu1_all.deb を展開する準備をしています ...
python3-compose (1.29.2-6ubuntu1) を展開しています...
以前に未選択のパッケージ docker-compose を選択しています。
.../8-docker-compose_1.29.2-6ubuntu1_all.deb を展開する準備をしています ...
docker-compose (1.29.2-6ubuntu1) を展開しています...
python3-dotenv (1.0.1-1) を設定しています ...
python3-texttable (1.6.7-1) を設定しています ...
python3-docopt (0.6.2-6) を設定しています ...
python3-packaging (24.0-1) を設定しています ...
python3-websocket (1.7.0-1) を設定しています ...
python3-dockerpty (0.4.1-5) を設定しています ...
python3-docker (5.0.3-1ubuntu1.1) を設定しています ...
python3-compose (1.29.2-6ubuntu1) を設定しています ...
docker-compose (1.29.2-6ubuntu1) を設定しています ...
man-db (2.12.0-4build2) のトリガを処理しています ...      
    

Dockerサービス開始
sudo service docker start
実行結果:
      xxx@hppc:~$ sudo service docker start
    

動作確認
sudo docker run hello-world

実行結果:
xxx@hppc:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete
ea52d2000f90: Download complete
Digest: sha256:85404b3c53951c3ff5d40de0972b1bb21fafa2e8daa235355baf44f33db9dbdd
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/      
    

sudoを付けずにdockerコマンドを実行したい場合は以下記事へ
https://masablg.blogspot.com/2026/03/dockerwsldocker.html


WSL, Docker

0 件のコメント:

その他の記事