6

What are the dependencies and steps to connect to a remote docker container from VSCode? So I can properly compile and run the code with the tools in my container environment?

I have tried to follow the instructions here without much luck:

My setup involves:

  • Host with VSCode, no docker installed, ssh client installed, ssh keys are in place
  • Server with VSCode, docker installed, ssh client and server installed
  • Docker container already running on Server

Host can connect to Server, through VSCode using the Remote Development Version: 0.17.0 extension, through Remote - SSH Version: 0.47.2 extension Version: 0.47.2

Server can connect to Docker container, through VSCode using the Remote Development Version: 0.17.0 extension, through Remote - Containers Version: 0.83.1 extension.

How do I connect Host to a Running Docker container?

UPDATE 1 Small advance

I have added this line to my ~/.config/Code/User/settings.json file. The option gets highlighed with a message unknown configuration setting

{
...
"docker.host":"tcp://localhost:23750",
...
}

Run this command in another terminal:

ssh -N -L localhost:23750:/var/run/docker.sock  <user>@<serveraddr>

And now I can see the running containers in Remote explorer > Containers > Other Containers. However, when trying to connect to it, I get the following error message.

Setting up container with bc1700db049858ba20f1c830bbeff6d6a4e04de58a2b35a61df1016788bc07db
Docker returned an error code 127, signal null, message: Command failed: docker system info
/bin/sh: docker: command not found
nico
  • 1,136
  • 1
  • 15
  • 33

2 Answers2

2

So, it appears that docker must be installed on the host machine to prevent the last mentioned error.

Note: docker service does not need to be running in the host (systemctl disable docker)

With this in mind, these are the steps.

Host:

  1. Install docker and ssh client
  2. Add your user to docker group
  3. Install VSCode
  4. Configure Server
  5. (After server config below): edit ~/.config/Code/User/settings.json with
"docker.host":"tcp://localhost:23750",
  1. Configure your ssh keys for the Server
  2. (After every reboot run on terminal: ssh -N -L localhost:23750:/var/run/docker.sock <user>@<serveraddr>)
  3. Run VSCode and install Remote Development extension. Restart VSCode
  4. Now you should see your running containers in VSCode Remote explorer > Containers > Other Containers

Server:

  1. Install docker and ssh server
  2. Install VSCode (this may not be a requirement on the server)
  3. Add your user to docker group and start your container
nico
  • 1,136
  • 1
  • 15
  • 33
  • Are we able to connect docker containers on different servers with this? – Jan33 Sep 20 '21 at 12:23
  • @Jan33 Until recent updates, yes. My docker and vscode are on versions from around Jan2021. Note that you must have docker binaries on the host. The service does not need to be running, but vscode requires the docker binaries. – nico Sep 21 '21 at 00:56
0

I realize this was already answered, but I stumbled across this while trying to set this up myself today. I found an additional issue I had appeared to be that my local SSH key had not been added to the agent. I was following the instructions here.

I am running Windows 10 Version 1909 Build 18363.1082.

After doing an ssh-add $Env:USERPROFILE\.ssh\id_rsa and restarting the ssh-agent, I was able to connect to the remote container without having to employ the ssh tunneling method you show above.

Ryan
  • 185
  • 11