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?

WSL(Ubuntu 22.04 LTS) に、DockerとDocker Composeをインストール

Last updated at Posted at 2024-03-31

環境

Windows10 + WSL(Ubuntu 22.04.3 LTS)
※Windows11でも確認済み

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
...

はじめに

最近何かと再インストールするタイミングが多いので、書き残し。

手順

事前に

  1. 初回立ち上げ前にPowershell(管理者実行)で以下を行う
wsl --set-default-version 2

2.仮想環境単体にPowershell(管理者実行)で以下を行う

wsl --shutdown
wsl --set-version <WSL管理名称> 2

※WSL管理名称 は wsl --list --verbose とかで確認

3.WSLのバージョンを最新にするためコマンドプロンプト(or Powershell)で以下を行う

wsl --update

※最新はsystemctlが面倒な設定なしで使えます

Dockerのインストール

# パッケージ更新
sudo apt -y update

# 必要なパッケージの追加
sudo apt install -y \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

# 証明書ダウンロード
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# 証明書登録
echo \
  "deb [arch=$(dpkg --print-architecture) 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

# パッケージ更新
sudo apt -y update

# Dockerのインストール
sudo apt -y install docker-ce docker-ce-cli containerd.io

# dockerを自動起動設定
sudo systemctl enable docker

# 操作ユーザーをグループに追加
sudo gpasswd -a $USER docker

# 一旦ターミナルを閉じる(グループ追加反映のため)
exit

Docker Compose のインストール (どちらかを実行すればOK)

  • aptで直接
# docker-composeインストール
sudo apt install -y docker-compose
  • Curlで取得したファイルベース
# フォルダ作成&移動
sudo mkdir -p /usr/local/libexec/docker/cli-plugins
cd /usr/local/libexec/docker/cli-plugins

# https://github.com/docker/compose/releases にアクセスして、最新をバージョンを確認(設定値は記載時最新)
DOCKER_COMPOSE_VERSION=v2.26.1

# compose の実行ファイルを取得
sudo curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64 -o docker-compose

# 権限変更
sudo chmod +x docker-compose

余談(以前の話)

  1. 自動起動
    以前は、sudoersを編集したり、nsloginからsystemctl実行して…というのをしないといけなかったのが面倒でしたが、現在はsystemctlがデフォルトで実行でき、ラクになりました。
  2. iptable
    以前は、iptableのバージョンを落とさないといけないタイミングがありましたが、今は必要ないみたいです。
    ※イメージが取得できなかったりしたはず…

最後に

ここ1~2年で細かいところが変わっていましたが、やっと落ち着いてきたように感じます。

参考

1
0
2

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?