参考文章:
https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
https://docs.docker.com/engine/install/debian/
https://blog.csdn.net/dqwjack/article/details/107699985
https://www.it1352.com/1794535.html
https://www.cnblogs.com/360linux/p/13662355.html
https://blog.csdn.net/A951860555/article/details/110038308
错误:docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
是因为docker没有启动,执行su root service docker start
报错:Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
报错:System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
打印启动命令:sudo dockerd --debug
修改密码:sudo passwd root
步骤:
wsl -l -v
wsl --set-default-version 2
vi /etc/resolv.conf 添加 nameserver dns
apt-get update
apt-get install curl
service network restart,/etc/init.d/networking restart,service networking force-reload
nano /etc/network/interfaces
sudo /sbin/dhclient
ifdown eth0
ifup eth0
reboot -f 强制重启
ping baidu.com
vi /etc/apt/sources.list
wslconfig /l 查看版本
wslconfig /u Ubuntu 注销
注意:
wsl安装后需要使用%TEMP%这个目录,狗则没有ip地址
=========================================================================
安装docker
注意:不同于完全linux虚拟机方式,WLS2下通过apt install docker-ce
命令安装的docker无法启动,因为WSL2方式的ubuntu里面没有systemd。上述官方get-docker.sh安装的docker,dockerd进程是用ubuntu传统的init方式而非systemd启动的。
service docker status
ps aux|grep docker
service docker restart
我们使用脚本安装
curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
安装完后,启动失败
直接在相应的目录下面创建
需要修改拉取资源的nano /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/debian buster main
deb https://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ buster/updates main
deb https://mirrors.tuna.tsinghua.edu.cn/debian buster-backports main
deb [arch=amd64] https://download.docker.com/linux/debian buster stable
deb http://ftp.cn.debian.org/debian buster main
创建一下文件 touch /etc/docker/daemon.json
debug模式启动: sudo dockerd --debug
用iptables初始化NAT网络,而Debian buster使用 nftables
而不是 iptables
,导致dockerd不能正常完成NAT初始化,出错退出。
处理方法是调用update-alternatives
强制Debian用iptables而不是nftables。
-
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
-
# for ipv6
-
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy