文章目录
前言
wsl是可以直接在Windows平台下运行Linux,相比传统的使用虚拟机来运行Linux系统,更加的轻便
一、开启win10的wsl功能
注意win10的版本要在19041 或更高版本
-
1、打开 适用于Linux的Windows子系统
打开控制面板 —> 程序和功能 —>启用或关闭Windows功能,勾选对应选项即可
-
2、打开系统虚拟机平台
打开控制面板 —> 程序和功能 —>启用或关闭Windows功能,勾选对应选项即可
随后重启电脑
二、安装wsl
第一步我们先在Microsoft Store中找到Ubuntu,点击安装。这里安装的是Ubuntu-18.04版本
安装成功后输入账号和密即可
三、升级wsl到wsl2
以管理员身份打开powershell,输入wsl -l
查看已经安装的子系统。
输入命令wsl --set-version Ubuntu-18.04 2
,这里的Ubuntu-18.04换成你的子系统名称(这里再强调一遍,必须是18917之后的版本)。
然后我们输入wsl -l -v
查看目前WSL版本,按下图显示就是安装好了
之后可以输入wsl --set-default-version 2
,使得之后安装的Linux子系统都安装到WSL2中。
四、wsl2中安装docker
1、先更新Ubuntu的apt安装源
sudo vim /etc/resolv.conf
添加:
nameserver 8.8.8.8
nameserver 223.5.5.5
nameserver 223.6.6.6
输入命令,备份 sources.list
sudo cp sources.list sources.list.bak
将sources.list文件改为如下:
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
2、更新源
sudo apt-get update
3、安装docker
依次执行下面代码:
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
$ sudo service docker start
安装成功后有一下提示
If you would like to use Docker as a non-root user, you should now consider
adding your user to the “docker” group with something like:
sudo usermod -aG docker lusifer
Remember that you will have to log out and back in for this to take effect!
4、检查docker安装正常:
- 启动docker
service docker start
- 检查docker的状态
service docker status
- 关闭docker服务
service docker stop
注意:如果使用apt直接安装docker的话,在wsl中无法使用systemctl命令的