win10home-docker

wsl如何升级到wsl2

reference:https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/wsl-containers

https://docs.docker.com/docker-for-windows/wsl/

https://docs.microsoft.com/zh-cn/windows/wsl/reference

https://docs.docker.com/docker-for-windows/install-windows-home/

https://www.cnblogs.com/temari/p/13188168.html

https://github.com/microsoft/WSL/discussions/5922

docker run -it ubuntu bash 这个镜像最小化了,需要运行

win10家庭版开启虚拟化

docker-for-windows需要开启hyper-v

https://docs.docker.com/docker-for-windows/troubleshoot/#hyper-v

win10 home版如何安装与禁止hyper-v

How To Enable Hyper-V On Windows 10 Home (itechtics.com) 下载的脚本内容如下

1
2
3
4
5
6
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
pause

按住windows键,输入Hyper-V,显示Hyper-V管理器

image-20210427014904381

wsl1切换到wsl2

wsl和wsl2可以互相切换,切换到wsl2后,不需要重新安装disto,docker Desktop for windows只支持wsl2,为了在win10家庭版下使用docker,需要进行切换

To check the WSL mode, run:

1
wsl.exe -l -v

To upgrade your existing Linux distro to v2, run:

1
wsl.exe --set-version (distro name) 2

To set v2 as the default version for future installations, run:

1
wsl.exe --set-default-version 2

运行wsl.exe --set-version (distro name) 2需要几分钟,此时wsl已经切换到wsl2,然后运行

wsl --distribution (distro name)启动wsl2的disto(不需要再重新安装:wsl install (distro name) )

运行docker run hello-world测试是否正常,如果出现”Unable to find image 'hello-world:latest' locally“,是因为docker还没有从hub上pull镜像到本地,稍等下就可以了

image-20210218150534442

列出所有安装的image

docker image ls

运行某个镜像

docker run image-name

docker替换源

docker在不同平台替换源的配置方式不同,参考dockerd | Docker Documentation,搜索configuration file可以找到windows平台的配置方式

docker官方推出了中国源:

1
2
3
"registry-mirrors": [
"registry.docker-cn.com"
]

docker-desktop-for-windows的config file

image-20210219225756676

位于C:\Users\hcf\AppData\Roaming\Docker\last-start-linux-daemon.json

或者C:\Users\hcf\.docker\daemon.json 这两个文件内容一致