WSL安装Docker避坑指北
发表于:2022-03-10 | 分类: IT
字数统计: 543 | 阅读时长: 2分钟 | 阅读量:

升级WSL

  • 查看已安装的WSL版本(Windows PowerShell中运行)

    1
    2
    wsl.exe -l -v

    显示如下:

    1
    2
    3
      NAME                   STATE           VERSION
    * Ubuntu-20.04 Running 1
    docker-desktop-data Stopped 2

    看到安装的为WSL1,据说WSL1不支持Docker,所以换成WSL2,至于WSL1 和WSL2的异同可参考比较 WSL 1 和 WSL 2

  • 安装WSL2 (Windows PowerShell中运行)

    1
    wsl.exe --set-version ubuntu-20.04 2

    显示如下:

    1
    2
    3
    正在进行转换,这可能需要几分钟时间...
    有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
    转换完成。

安装Docker

在WSL中运行如下命令:

1
2
3
4
5
6
7
8
sudo apt-get remove docker docker-engine docker.io
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce

Root用户启动Docker

1
2
3
sudo su
export DOCKER_HOST=tcp://localhost:2375
service docker start

显示如下:

1
* Starting Docker: docker

测试(还是在root用户)

1
docker version

报错

以下是报错信息:

1
2
3
4
5
6
7
8
9
10
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:33 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

修复

回到普通用户运行

  • 编辑环境变量

    1
    2
    3
    4
    5
    vi ~/.bashrc

    # 在最下面添加一行:
    export DOCKER_HOST='unix:///var/run/docker.sock'
    source ~/.bashrc
  • 再次测试

    1
    sudo docker version

    显示如下表明成功:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    Client: Docker Engine - Community
    Version: 20.10.12
    API version: 1.41
    Go version: go1.16.12
    Git commit: e91ed57
    Built: Mon Dec 13 11:45:33 2021
    OS/Arch: linux/amd64
    Context: default
    Experimental: true

    Server: Docker Engine - Community
    Engine:
    Version: 20.10.12
    API version: 1.41 (minimum version 1.12)
    Go version: go1.16.12
    Git commit: 459d0df
    Built: Mon Dec 13 11:43:42 2021
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: 1.4.13
    GitCommit: 9cc61520f4cd876b86e77edfeb88fbcd536d1f9d
    runc:
    Version: 1.0.3
    GitCommit: v1.0.3-0-gf46b6ba
    docker-init:
    Version: 0.19.0
    GitCommit: de40ad0

参考

代码获取

关注公众号“生信之巅”,聊天窗口回复“”获取下载链接。

生信之巅微信公众号 生信之巅小程序码

敬告:使用文中脚本请引用本文网址,请尊重本人的劳动成果,谢谢!Notice: When you use the scripts in this article, please cite the link of this webpage. Thank you!

上一篇:
PGCGAP - the Prokaryotic Genomics and Comparative Genomics Analysis Pipeline v1.0.33
下一篇:
Nanopore基因组组装