• 记录一次wls2上ubuntu20.04版本中安装docker


    为了方便使用docker容器演示,在win10上安装了wls2以及ubuntu20.04系统

    1、配置阿里云源

    更换apt源并修改DNS解析

    1. 更换apt源
    2. 修改DNS
     cat /etc/resolv.conf 
    # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
    # [network]
    # generateResolvConf = false
    nameserver 10.18.104.246
    nameserver 61.178.0.93
    nameserver 192.168.6.200
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2、配置root秘密并开启远程登录

    1. 配置密码
    sudo su
    passwd root
    
    • 1
    • 2
    1. 开启远程登录
    vim /etc/ssh/sshd_config
    # 配置一下选项
    Port 22
    #AddressFamily any
    ListenAddress 0.0.0.0
    
    #PermitRootLogin prohibit-password
    PermitRootLogin yes
    
    PasswordAuthentication yes
    
    # 安装ssh服务
    apt-get install openssh-server openssh-client
    
    /etc/init.d/ssh start
    
    ifconfig
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    即可使用远程工具进行连接

    3、安装docker

    wget https://download.docker.com/linux/ubuntu/gpg
    sudo apt-key add gpg
    
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述
    修改service

    远程docker server开启了tcp连接,即在 /lib/systemd/system/docker.service 中的ExecStart=/usr/bin/dockerd 一句后面追加tcp访问协议,如下

    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    #ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    ExecStart=/usr/bin/dockerd -H  unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
    ExecReload=/bin/kill -s HUP $MAINPID
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    4、重启wls的ubuntu

    # 管理员运行powershell
    Get-Service LxssManager | Restart-Service
    
    # 启动sshd
    /etc/init.d/ssh start
    # 启动docker
    service docker start
    service docker status
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    5、曲线救国

    wls中启动docker可能会遇到各种问题,这时候我们可以考虑曲线救国的方式,那么多容器化工具,podman、containerd等,为什么非要使用docker呢
    这里使用podman代替docker(目的是为了方便容器化操作)

    # 卸载上一步安装的
    dpkg --get-selections | grep -v deinstall | grep docker | awk '{print $1}'
    docker-ce
    docker-ce-cli
    docker-ce-rootless-extras
    docker-compose-plugin
    docker-scan-plugin
    
    # 删除查询到的docker被安装的信息后删除
    sudo apt-get autoremove docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin  docker-scan-plugin -y
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    安装podman

    # 执行以下命令导出' /etc/os-release '文件中的环境变量。
    . /etc/os-release
    
    # 添加具有稳定版本的 podman 存储库,并使用以下命令将 GPG 密钥添加到您的系统。
    echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
    
    curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -
    
    # 更新/刷新 Ubuntu 存储库并将所有软件包升级到最新版本。
    sudo apt update
    sudo apt -y upgrade
    
    # 安装
    sudo apt install podman -y
    
    podman version
    
    # 添加别名(骗骗自己,假装使用的是docker)
    sudo vim /root/.bashrc
    vim .bashrc
    # 添加别名
    alias docker='podman'
    
    source .bashrc
    
    
    # 测试
    sudo docker version
    sudo docker info
    
    • 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
    • 29

    在这里插入图片描述

    参考链接:
    https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11YfnocC
    https://blog.51cto.com/wdndltg/5189597
    https://blog.csdn.net/bean_business/article/details/112278504
    https://blog.csdn.net/XhyEax/article/details/105560377
    https://www.jianshu.com/p/95742c89a3ba
    https://zhuanlan.zhihu.com/p/457866408
    https://www.cnblogs.com/it-tsz/p/11107510.html
    https://geray-zsg.github.io/2022/01/Docker%E5%9F%BA%E7%A1%80/

  • 相关阅读:
    二叉树的层平均值-力扣
    【FAQ】【ArkUI】ETS 怎么创建实体类和引用
    【如何去掉Unity点击运行时,Photon的警告弹窗】
    直播协议 python 常见直播协议
    如何实现Laravel 5.1 分页功能及自定义分页样式
    JDK数组阻塞队列源码深入剖析
    Unity 佳能SDK 及数据获取
    kr 第三阶段(三)调试器
    svn log 高级命令解释
    用户侧功能
  • 原文地址:https://blog.csdn.net/Entity_G/article/details/126286569