- 投稿日:2023年06月05日 20時15分20秒
- 更新日:2023年06月05日 20時20分30秒

WLS-Ubuntuにdockerをインストールする
詳細
WSL2のUbuntuにdockerをインストールします。
準備
# 既存を削除
sudo apt-get remove docker docker-engine docker.io containerd runc
リポジトリのセットアップ
# aptのパッケージインデックスを更新
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
# Docker の公式 GPG 鍵を追加します。
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 安定版(stable)リポジトリをセットアップ 最新版等に変更可
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
Docker Engine のインストール
# Docker Engine、containerd、Docker Compose の最新版をインストール
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 確認
sudo docker run hello-world
設定・後処理
wsl.confにDocker起動コマンドを書く
wslのUbuntuの場合systemctlコマンド等ないため、起動後毎回起動コマンドを実行しなくてはなりません。これを自動化します。
sudo nano /etc/wsl.conf
通常だと存在しないファイルのため新規作成されます。
[boot]
command = service docker start;
あとはWSLを再起動して反映させてください。
wslの設定
[wsl2]
memory=4GB
swap=4GB
おまけ
今回はWSLのUbuntu20.04からUbuntuへのディストリビューションの変更対応で行っていたのですが、どうやらdockerのバージョンが上がり、docker-composeが含まれるようになったためdocker-composeが使えないという事態が発生した。
その際のエラー
$ docker-compose build
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
最新のバージョンを入れても対応できるのだと思いますが、今回はシンプルにコマンドを変更
$ docker compose build
[+] Building 3.6s (30/30) FINISHED
############### 以下省略 ###############
ちなみにUbuntu20.04から変更する理由はHDDを圧迫するから。170GB近くあってビビった。