win10使用子系统RunDocker
执行docker命令时会提示:
cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running
只需要通过以管理员身份运行Ubuntu,然后在窗口执行sudo service docker start
-
1.Windows执行
-
管理员运行运行Hype-v
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
-
启用虚拟机功能
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
将 WSL 2 设置为默认版本
wsl --set-default-version 2
列出版本wsl --list --verbose
设置版本wsl --set-version <distribution name> <versionNumber>
>>>wsl --set-version Ubuntu-20.04 2
-
win 安装 DockerForWindow
-
在 Resources 的WSL Integration中设置要从哪个 WSL2 发行版中访问 Docker,如下图使用的是 Ubuntu
重启 Docker desktop for Windows,重启完成后我们就可以在 WSL2里面使用 docker 命令了
-
-
2.Linux操作
# 设置服务自启 sudo systemctl enable docker.service #将登陆用户加入到docker用户组中 sudo gpasswd -a $USER docker #更新用户组 newgrp docker # 重启 docker 服务 sudo service docker restart sudo systemctl restart docker
设置ubuntu链接远程docker daemon
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
效果