将WSL VSCode扩展名连接到Windows中安装的Docker

时间:2019-03-27 22:13:58

标签: docker visual-studio-code windows-subsystem-for-linux

我已在Windows 10 Pro计算机上安装了Linux的Windows子系统(WSL)。遵循this教程之后,我在Windows上设置了docker以使用WSL。在WSL的命令行中,docker工作正常。我构建了多个图像,并在WSL中运行了该图像。

我还在WSL中安装了Microsoft Visual Studio Code。我正在Windows的X服务器的帮助下使用它(VcXsrv)。在VSCode内部,我已经安装了docker扩展。即使我在设置中正确设置了Docker主机,它仍未连接到Docker。

我知道这是一个扭曲的设置,我可以使用适当的Linux安装来使其正常工作。但是我需要知道是否有可能使其在当前设置中工作,因为这对我很重要。任何帮助将不胜感激。

抛出的确切错误消息是:

Unable to connect to Docker. 
Please make sure you have installed Docker and that it is running. 
Also, make sure you've followed the Linux post-install instructions:
"Manage Docker as a non-root user". 
Details: connect ECONNREFUSED 127.0.0.1:80

我的VSCode settings.json文件:

{
    "editor.fontFamily": "'Fira Code'",
    "terminal.integrated.shell.linux": "/bin/zsh",
    "terminal.integrated.fontFamily": "monospace",
    "editor.fontLigatures": true,
    "terminal.integrated.fontWeightBold": "normal",
    "editor.fontWeight": "500",
    "python.venvPath": "/home/r2m/Work/venv",
    "terminal.integrated.rendererType": "dom",
    "git.autofetch": true,
    "workbench.colorTheme": "Material Theme Darker High Contrast",
    "docker.host": "tcp://localhost:2375"
}

docker info的输出在WSL中运行:

Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 16
Server Version: 18.09.2
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155d028201
ID: PBQD:BCLL:MYXY:6OFR:KJB2:UK46:VQWG:ELYT:6NGO:42QP:4SRK:FHO2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 47
 System Time: 2019-03-27T22:09:33.2435878Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

1 个答案:

答案 0 :(得分:1)

这很奇怪:<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.cisco.com/ast/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header/> <ns2:Body> <ns1:SelectCmDevice> <CmSelectionCriteria xsi:type="ns1:CmSelectionCriteria"> <Class xsi:type="tns:DeviceClass">Phone</Class> <ns1:SelectBy xsi:type="ns3:string">Name</ns1:SelectBy> </CmSelectionCriteria> </ns1:SelectCmDevice> </ns2:Body> </SOAP-ENV:Envelope> 。该扩展不应连接到80端口。您还记得在任何地方设置吗?

目前,这种组合效果很好:

  1. 带有远程开发扩展https://aka.ms/vscode-remote/download/extension的VSCode Insider Windows
  2. 适用于Windows的Docker
  3. WSL上的
  4. Docker CE CLI

顺便说一句,该指南有点过时了。您应该遵循官方指南在Linux https://docs.docker.com/install/linux/docker-ce/ubuntu/上安装 docker-cli ,并遵循本指南来设置VSCode https://code.visualstudio.com/docs/remote/containers

在Linux上,您需要安装Details: connect ECONNREFUSED 127.0.0.1:80,而无需执行docker-cli

不再建议在WSL中使用VSCode Linux。但是,Docker扩展也应该在X服务器上的VSCode中开箱即用。

到本月底,还将推出具有更好兼容性的基于VM的新WSL 2。