12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WSL2 に Docker Engine をインストール(Docker Desktop なし)

Last updated at Posted at 2022-01-28

前回、WSL2で Ubuntu20.04LTS環境の構築を行いました。
Docker を使いたいため、WSL2 に Docker Engineをインストールした際の手順を残します。
Docker Desktop なしでインストールしていますが、WSL2公式においては Docker Desktop for Windows を利用することを推奨しています。

目次

  1. Install docker on wsl
  2. Install docker-compose on wsl

1. Install docker on wsl

1-1 パッケージ一覧を更新
$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
(略)
Reading state information... Done
251 packages can be upgraded. Run 'apt list --upgradable' to see them.
1-2 パッケージのインストール
$ sudo apt install -y \
>     ca-certificates \
>     curl \
>     gnupg \
>     lsb-release
Reading package lists... Done
Building dependency tree
(略)
Running hooks in /etc/ca-certificates/update.d...
done.

ca-certificates : Ubuntu ベースの Docker コンテナで SSL 接続をするため

1-3 Dockerのofficial_GPG_key追加
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
1-4 Dockerリポジトリ情報の登録
$ 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
1-5 パッケージ一覧を更新
リポジトリ情報を更新したので念のため
$ sudo apt update
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [13.5 kB]
(略)
Fetched 2818 kB in 4s (759 kB/s)
Reading package lists... Done
1-6 Docker Engine のインストール
$ sudo apt install -y docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree
(略)
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3) ...
1-7 Docker Group にユーザを所属させる
sudo無しでdockerコマンド実行させるため
$ sudo usermod -aG docker $USER
1-8 Docker service 起動設定
WSL起動時にDockerService起動させるため(パスワード要求される)
cat <<EOF >> ~/.bashrc
# For Docker service start
sudo /etc/init.d/docker start
EOF

WSL2ではsystemdがPID1で起動しない。
WSL2起動時にsystemd で docker daemonを起動させる方法があるのかもしれませんが、分かりません。

1-9 動作確認
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
(略)
Hello from Docker!
This message shows that your installation appears to be working correctly.
(略)

2. Install docker-compose on wsl

2-1 docker-compose インストール
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2-2 実行権限付与
$ sudo chmod +x /usr/local/bin/docker-compose
2-3 シンボリックリンク設定
docker-composeで実行できるように
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
2-4 バージョン確認
$ docker-compose --version
docker-compose version 1.24.1, build 4667896b
12
11
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
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?