docker - 将 WSL VSCode 扩展连接到安装在 Windows 中的 docker

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

我已经在我的 Windows 10 专业版机器上安装了适用于 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

最佳答案

这很奇怪:Details: connect ECONNREFUSED 127.0.0.1:80 .分机不应连接到 80 端口。你还记得在任何地方设置这个吗?

目前这个组合效果很好:

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

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

在 Linux 上,您需要安装 docker-cli不需要做 Post-installation steps for Linux .

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

到月底,兼容性更好的新的基于VM的WSL 2也将到来。

关于docker - 将 WSL VSCode 扩展连接到安装在 Windows 中的 docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55387278/

相关文章:

javascript - typescript、jsconfig.json、bower.json 和 vs-code 协同工作

python - 导入破坏了 pytest 的 VSCode 测试

php - 使用 PHP、Composer、NPM 通过 WSL 设置 LEMP 的网络问题

Docker 构建命令在 WSL 2 Ubuntu 18.04 中挂起

visual-studio-2012 - Visual Studio Code 和 VS 2012 可以安装在同一台计算机上吗?

linux - 在 Windows 10 上使用 bash 定位我的串行端口时遇到问题

java - 为 Spring Cloud 配置服务器创建 docker 文件

docker - 使用 Docker 安装 msodbcsql17 时出现问题

docker - Centos 7 安装特定版本的docker ce

docker - 构建具有 "RUN apt-get update"的 Dockerfile 给我 "jailing process inside rootfs caused ' 权限被拒绝'”