Windows10中未安装Docker Desktop,而是通过WSL2安装linux内核docker。在使用VSCode Remote运行远程容器时出现问题,无法正常使用。记录解决方案如下:
前提条件
WSL2 安装 Docker Without Docker desktop
Windows 不安装Docker Desktop使用Docker命令
下载单独的windows docker文件
解压并设置环境变量
将解压路径设置至环境变量path中
docker -v 验证成功
docker ps 失败
接下来继续解决
WSL2 公开 Docker 守护程序并为其创建上下文
在 WSL2 中,更改服务配置以在本地主机上额外公开 Docker 守护程序:
1 | sudo cp /lib/systemd/system/docker.service /etc/systemd/system/ |
Windows 设置DOCKER_HOST
增加环境变量:
DOCKER_HOST = tcp://localhost:2375
验证:
docker ps
docker images
docker run hello-world
均可成功
Configure VSCode to access to WSL2 docker
To do so, click on the icon (?) on the top right of the section “Containers” and select “Edit settings…”
You’ll get around 56 settings and you search for “Docker:Host” where you put the line “tcp://localhost:2375” where you can replace the highlighted ip address by the one you got before
Once done, you come back to the panel and you click on “refresh” icon (top right of each sections) and you would get information from your dockerd running in WSL2
使用 VS Code 在远程容器中开发
问题解决,参照下文继续使用 VS Code 在远程容器中开发
参考资料
Is it possible to install only the docker cli and not the daemon