2

Original Post

I have a Windows workstation with WSL2 and Docker installed that I am able to use for container based development in VS Code. I would like to be able to develop inside the containers on this system remotely. I am able to SSH directly into the WSL2 environment on the workstation and am able to start the docker daemon without logging directly into Windows by creating a Task to start the daemon automatically as described here: https://stackoverflow.com/a/59467740/10692741

However when I try to access Docker on the remote machine by following this guide: https://code.visualstudio.com/docs/remote/containers-advanced#_developing-inside-a-container-on-a-remote-docker-host, I get the following error:

error during connect: Get http://docker/v1.24/version: net/http: HTTP/1.x transport connection broken: malformed HTTP status code "\x00c\x00o\x00m\x00m\x00a\x00n\x00d\x00"

I have also tried connecting via a SSH tunnel as outlined here: https://code.visualstudio.com/docs/remote/troubleshooting#_using-an-ssh-tunnel-to-connect-to-a-remote-docker-host and am unable to connect to Docker as well.

Has anyone had success with a setup like this? Or is this not supported due to limitations with Docker on Windows, WSL2, and/or Windows OpenSSH implementation?

Update: 2021-01-21

When I SSH into the Windows machine remotely, I am able to see the docker containers in the VS Code extension. I am able to start them, stop them, and enter into them with the shell. However, when I try to attach VS Code I get same error shown above.

Things that may have possibly affected this over the past couple days:

Also I want to note that the I've tried using Windows, Mac, and Linux as the local machine. With Mac and Linux I am able to open a remote session into the Windows machine, but from the Windows local machine I am able to SSH into the remote Windows machine but cannot open a remote connection in VS Code for some reason.

  • From what I know of all of those components, I'm fairly certain there's a way to make the Remote/WSL2/SSH/Docker workflow work, but it will probably require jumping through a few hoops (as you've already noticed). I don't have enough time to dig into this too deeply right now, but let me start by asking you to confirm that you can SSH from the development machine into the WSL2 instance on the remote machine. I see in your question a confirmation that you can "SSH directly into the WSL2 environment on the workstation", which I think means you are doing that step locally, but I'm not sure. – NotTheDr01ds Jan 19 '21 at 02:52
  • Yes, I set up WSL2 as the default shell for OpenSSH connections according to this guide: https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine, the only difference being I set the default as `wsl.exe` instead of `bash.exe`. So when I authenticate via password or keys, it will automatically open a shell in WSL2. – cptchloroplast Jan 19 '21 at 18:01
  • Ah, good. I use a slightly different technique, but I like that one as well. Ok, so at least we don't need to worry about that part of the solution for your case. – NotTheDr01ds Jan 19 '21 at 22:21

1 Answers1

0

Ok, I was able to get this working using the port/socket forwarding technique. For sake of clarity, I'll use:

  • local development workstation, local workstation, or just workstation to indicate the computer from which we wish to use VSCode to access Docker containers on ...

  • the remote Docker host, remote, or just Docker host

Sanity check -- Do you have Docker Desktop installed on both systems? On the local development workstation, you can skip the WSL2 integration, but you'll at least need the client tools, since the VSCode extension uses them.

Steps I took:

  • I already had Docker with WSL2 integration set up on my main system (which for the purposes of this exercise, became my remote Docker host), along with VSCode, so I knew everything was working there. It sounds like that was your starting point as well.

  • On another system on the same network (accessed with RDP to make it simple), I already had VSCode installed as well, with the Remote Development Extension Pack. I also have WSL on that system, but only a v1 instance there. Not that WSL on the workstation should be a factor at all for the purposes of this exercise.

  • I installed Docker Desktop for Windows on that local development workstation.

  • I also installed the Docker extension for VSCode, since I didn't yet have it on the local development workstation.

  • On the workstation, I was not yet set up to SSH from PowerShell into my WSL Ubuntu distro on the remote. From PowerShell on the workstation, I generated an ECDSA key (per this and other documents) and added the public key to my authorized_keys on the the remote.

  • On the workstation, I started the OpenSSH Authentication Service and added the newly created key to the agent (in PowerShell) with ssh-agent add ~\.ssh\id_ecdsa.

  • I logged out of the workstation and back in so that the path changes were picked up for the Docker desktop install.

  • I was then able to ssh from Powershell on the local to Ubuntu/WSL on the remote with the port forwarding. Since I'm using the Windows 10 OpenSSH server as a jumphost to my WSL SSH servers, my command looked slightly different (with a -o "ProxyCommand ... mainly), but overall the structure is the same as the one listed in the "SSH Tunnel" doc you linked in your question.

  • On the remote (manually, not through any integration from the local), I did a basic docker run -it --rm Ubuntu and left it open.

  • On the local, from PowerShell, I set the DOCKER_HOST environment variable via [System.Environment]::SetEnvironmentVariable("DOCKER_HOST","tcp://localhost:23750").

  • I was then able to see the remote container using docker ps on the local. I could also docker exec -it containername bash into it remotely.

  • Of course, the above two steps aren't needed in the long term for VSCode, they were just part of my process to make sure everything was up and running (since, as you might expect, I did have several points at which I failed during this process).

  • So with that working, it was a simple matter in VSCode to change the Docker extension's DOCKER_HOST setting to tcp://localhost:23750. And voila, I could see all images on the remote as well as attach to them from VSCode.

Other thing(s) to check

I'll add to this list if we find additional reasons why it might not be working, but for now:

  • You mention that you are starting the Docker Desktop daemon automatically at startup via Task Manager, but you don't mention anything about the WSL2 instance. However, since you are able to ssh into it, I assume you have a way to bring it up as well? My experience has been that, unless the owning user is logged in, WSL terminates any instances after a few seconds, even if a service is running. There's a workaround, I believe, that I can dust off if this is a problem.
NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • WSL2 seems to work fine without having an active user logged into Windows, although I am using my Windows user to open the SSL connection so that might be why. I updated the original post with more details, I've made some progress but am still unable to attach VS Code to the remote containers. – cptchloroplast Jan 22 '21 at 00:26