0
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?

More than 3 years have passed since last update.

Debian10 on WSL2 にDocker Engineをインストールする方法

Last updated at Posted at 2021-06-26

背景

Windows 10 HomeでDockerが必要になったが、Docker Desktop on Windowsは使いたくないため、WSL2でDockerをサポートしているLinuxをインストールし、そこへDocker Engineをインストールすることにした。

本稿の記述範囲

具体的には、以下の作業を実施した。

  1. WSL2を有効にする
  2. Microsoft StoreからDebianをインストールする
  3. DebianにDockerをインストールする

Debian on WSL2のインストールまでは問題なく実施できたが、Dockerのインストールでつまずいたため、本稿では問題の内容と解決方法を記す。

環境

  • Windows
    • エディション : Windows 10 Home
    • バージョン : 20H2
    • OSビルド : 19042.1052
  • Debian cat /etc/os-releaseにより確認した
    • PRETTY_NAME="Debian GNU/Linux 10 (buster)"
    • NAME="Debian GNU/Linux"
    • VERSION_ID="10"
    • VERSION="10 (buster)"
    • VERSION_CODENAME=buster
    • ID=debian
  • Docker
    • Docker version 20.10.7
    • build f0df350

Debian on WSL2にDocker Engineをインストールする方法

Dockerの公式ページにDebianへDocker Engineをインストールする方法が書かれたページがある。今回は、推奨された方法であるDocker公式リポジトリからインストールすることにした。

問題発生

公式ページに従ってDockerをインストールした後、起動しようとすると、以下のようなエラーが発生し、起動できなかった。

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

デーモンを起動しようと思い、以下を実行したが、解決できなかった。

$ sudo service docker start
grep: /etc/fstab: No such file or directory
[ ok ] Starting Docker: docker.

解決策

WSLの公式GitHubのDiscussionのとあるページに解決策が載っていた。
どうやらiptableをレガシーモードで動かさないといけないらしい。

以下のコマンドでインストールすれば、無事にDocker Engineが動いた。

$ sudo apt install apt-transport-https  ca-certificates  curl gnupg-agent software-properties-common iptables
$ sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
$ /sbin/iptables --version
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io
$ sudo service docker start
$ sudo docker ps -a
$ sudo docker run --rm hello-world

まとめ

Debian10 on WSL2にDocker Engineをインストールする場合、Dockerの公式ページの手段では不十分なため、追加でiptablesに関する設定変更が必要だ。

参考ページ

0
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
0
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?