VS Code: connect a docker container in a remote server

Hakjin Lee picture Hakjin Lee · Feb 27, 2020 · Viewed 10.9k times · Source

I want to work in a container in a remote server. But it doesn't work.

Environment:

Local: Windows 10

Local Terminal for ssh: WSL in Windows 10

Server: Ubuntu 18.04

I checked these two articles.

https://code.visualstudio.com/docs/remote/containers-advanced https://code.visualstudio.com/docs/containers/ssh

I followed these steps.

  1. I installed [Remote Development] extension in VS Code.
  2. Remote-SSH: Connect to host. It works fine.
  3. I Installed [Docker] extension on the remoter server.
  4. Now I can see my containers and images in a docker tab.
  5. I clicked one container and clicked [Attach Visual Studio Code] and it says There are no running containers to attach to.

enter image description here

Answer

cantonjf picture cantonjf · May 11, 2020

I solve this issue using SSH tunneling following the steps found in https://florian-kriegel.de/blog/?p=234

Summarizing:

  1. Set (or add) "docker.host": "tcp://localhost:23750" in settings.json in VSCode.
  2. Open a SSH tunnel like this in your local machine changing the user and hostname by the remote machine (where the docker daemon is running) credentials: ssh -NL localhost:23750:/var/run/docker.sock user@hostname.
  3. Now, in the docker tab, you will be able to see and attach to containers in the remote machine.

Note that the Remote SSH Extension is not used in this case.