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

23 篇文章 0 订阅
3 篇文章 0 订阅

为了方便使用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

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

  1. 配置密码
sudo su
passwd root
  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

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

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

在这里插入图片描述
修改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

4、重启wls的ubuntu

# 管理员运行powershell
Get-Service LxssManager | Restart-Service

# 启动sshd
/etc/init.d/ssh start
# 启动docker
service docker start
service docker status

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

安装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

在这里插入图片描述

参考链接:
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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值