wsl2、debian11、docker

wsl2安装debian 11后正常启动docker记录

安装vim

apt-get install vim

切换安装源Alibaba

  1. 修改文件sudo vim /etc/apt/sources.list 在sources.list文件最前面添加以下条目

    deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
    deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
    deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
    deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
    deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
    deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
    deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
    deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
    
  2. 更新镜像源apt-get update

docker手动安装

  1. 卸载旧版本

    sudo apt-get remove docker \
             docker-engine \
             docker.io \
             containerd \
             runc
    sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
    sudo rm -rf /var/lib/docker
    sudo rm -rf /var/lib/containerd
    
  2. apt 源使用 HTTPS 传输的软件包以及 CA 证书, 确保软件下载过程中不被篡改。

     sudo apt-get install \
      apt-transport-https \
      ca-certificates \
      curl \
      gnupg \
      lsb-release
    
  3. 添加软件源的 GPG 密钥,确认所下载软件包的合法性

    ## 阿里云
    curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
    
    ## 官方源
    #  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
    ## GPG密钥需要与实际使用的安装源对应
    
  4. 向 sources.list 中添加 Docker 软件源:

    $ echo \
      "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    # 官方源
    # $ echo \
    #   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
    #   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    
    # 在一些基于 Debian 的 Linux 发行版中 $(lsb_release -cs) 可能不会返回 Debian 的版本代号,例如 Kail Linux (opens new window)、 BunsenLabs Linux (opens new window)。
    # 在这些发行版中我们需要将下面命令中的 $(lsb_release -cs) 替换为 https://mirrors.aliyun.com/docker-ce/linux/debian/dists/ 中支持的 Debian 版本代号,例如 buster。
    
  5. 更新sudo apt-get update

  6. 安装sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

脚本安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,Debian 系统上可以使用这套脚本安装,另外可以通过 --mirror 选项使用国内源进行安装:

curl -fsSL get.docker.com -o get-docker.sh 
# 添加--mirror Aliyun
sudo sh get-docker.sh --mirror Aliyun

# 执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker 的稳定(stable)版本安装在系统中。

配置镜像源

  1. 新建文件夹mkdir /etc/docker(避免vim新建文件后无法保存)

  2. 修改/新建文件sudo vim /etc/docker/daemon.json

    {
      "registry-mirrors": [
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com"
      ]
    }
    

启动docker

service docker start
# service docker restart

# 基本信息
docker info
# 检查安装版本
docker --version
# 校验Docker
docker run hello-world

wsl下使用systemctl容易出问题,用service替换systemctl SysV init的命令

参考连接

  1. 修改安装源open in new window
  2. docker安装open in new window
  3. 错误处理open in new window
Last Updated:
Contributors: haizhiguang