How to set a remote connection to a Vagrant container using "Visual Studio Code Remote - SSH"?
Asked Answered
S

2

15

I'm exploring the new set extensions called VSCode Remote Pack and I want to connect to a Vagrant container using the Remote Container extension. Using a Windows 10 OS, how could I do that?

I tried the extension but it requests me to have Docker installed, what I suppose from that is that it only works for Docker containers. But I wonder if somebody have already managed to connect to a Vagrant box.

This are the docs from the extension: https://code.visualstudio.com/docs/remote/containers

Spinescent answered 3/5, 2019 at 16:49 Comment(0)
S
11

Sorry for updating this so late.

The solution was pretty simple, as @MnZrk commented, what it needs to be done for setting up the connection is the following:

  • Run vagrant ssh-config > some-file.txt. This will generate a file with the configuration to run using SSH. Here an example of that file:
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/User/project/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes
  ForwardX11 yes

Notice that the host name is default, you could rename it to whatever you want so you could identify it more easily.

  • Copy the content of some-file.txt inside your SSH configuration file. This file could be edit directly from vscode by pressing F1 and writing Remote-SSH: Open Configuration File..., then you select the file you use for ssh configuration. After that file opens, just copy the content of some-file.txt there.

  • Finally, just press again F1 and type Remote-SSH: Connect to Host..., choose the connection with the host name default or the want you wrote in the first step, and that's all.

Spinescent answered 4/6, 2020 at 17:8 Comment(0)
R
11

VS Code Remote containers currently only support Docker (its implementation executes docker commands). Please open a feature request if you would like to see other tools supported.

As an alternative, you could try using Remote SSH to connect to vagrant containers. That should work but will require some extra container setup

Rufena answered 3/5, 2019 at 21:9 Comment(5)
You're right! Actually, it was pretty easy to connect using Remote SSH :DSpinescent
@CarlosCórdovaS. Can you explain how you did this? I'm having trouble with the user@hostname step. Not sure where I get these values from.Bostwick
Dito as above. I can SSH into the server, but not sure how to connect to a remote container.Titulary
@Bostwick You get a ssh config from vagrant ssh-config and put it to the config file VSCode uses by F1 -> Remote-SSH: Open configuration File... The vagrant container should appear in the F1 -> Remote-SSH: Connect to Host... list.Nicolella
So once you have connected to a vagrant VM, how do you attach a debugger to a Docker container inside said VM?Pornocracy
S
11

Sorry for updating this so late.

The solution was pretty simple, as @MnZrk commented, what it needs to be done for setting up the connection is the following:

  • Run vagrant ssh-config > some-file.txt. This will generate a file with the configuration to run using SSH. Here an example of that file:
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/User/project/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes
  ForwardX11 yes

Notice that the host name is default, you could rename it to whatever you want so you could identify it more easily.

  • Copy the content of some-file.txt inside your SSH configuration file. This file could be edit directly from vscode by pressing F1 and writing Remote-SSH: Open Configuration File..., then you select the file you use for ssh configuration. After that file opens, just copy the content of some-file.txt there.

  • Finally, just press again F1 and type Remote-SSH: Connect to Host..., choose the connection with the host name default or the want you wrote in the first step, and that's all.

Spinescent answered 4/6, 2020 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.