1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2のUbuntuでdocker構築

Posted at

はじめに

WSL2上のUbuntuにdockerを構築したのでその備忘録です。

記事の要約

  • WSL上のUbuntuにDockerをインストールする手順を説明
    • 古いDockerパッケージを削除し、新しいGPGキーを追加してから、DockerとDocker Composeを正常にインストールすることができる
    • 注意点として、古いパッケージを削除しないとインストールに失敗することがある
  • sudoなしでDockerを実行するためにユーザーをdockerグループに追加する必要がある

手順

インストール

WSLでUbuntuを起動

PS C:\Users\Nichi\work> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-24.04    Stopped         2
PS C:\Users\Nichi\work> wsl -d Ubuntu-24.04

古いDocker関連パッケージを削除

sudo apt-get remove docker docker-engine docker.io containerd runc

パッケージリストの更新

sudo apt-get update

必要な依存パッケージのインストール

sudo apt-get install -y ca-certificates curl gnupg lsb-release

Docker公式GPGキーの追加

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

再度パッケージリストの更新

sudo apt-get update

dockerのインストール

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

インストールできたか確認

nichi@Priv-001:/mnt/c/Users/Nichi/work$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:5b3cc85e16e3058003c13b7821318369dad01dac3dbb877aac3c28182255c724
Status: Downloaded newer image for hello-world:latest

Hello from Docker!

sudoなしでDockerを実行する設定

ユーザーをdockerグループへ追加

sudo usermod -aG docker $USER

Docker composeのインストール

既に入ってました。

nichi@Priv-001:/mnt/c/Users/Nichi/work$ sudo apt-get install docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
docker-compose-plugin is already the newest version (2.32.1-1~ubuntu.24.04~noble).
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.

バージョン確認

nichi@Priv-001:/mnt/c/Users/Nichi/work$ docker compose version
Docker Compose version v2.32.1

まとめ

  • 普通にUbuntu上に構築するのと変わらない
  • 古いDocker関連パッケージ削除を端折ると失敗するで注意
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?