I resolved this problem by switching to the remote server's Docker context on my local machine:

docker context create some-context-label --docker "host=ssh://user@remote_server_ip"

docker context use some-context-label

docker ps
# A list of remote containers on my local machine! It works!

After that:

  1. Connect via Remote-SSH to the container server
  2. Right click relevant container -> the "Attach Visual Studio Code"

That works for me.

(Note: One would think that I should be able to just use my local VSCode (skip step 1) to connect to said remote container after switching my local context, but VSCode complains Failed to connect. Is docker running? in the Docker control pane.)

Answer from Daniel on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › develop-remote-host
Develop on a remote Docker host
November 3, 2021 - Docker does not support mounting (binding) your local filesystem into a remote dev container, so Visual Studio Code's default devcontainer.json behavior to use your local source ...
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › ssh
Connect to remote Docker over SSH
November 3, 2021 - We recommend using the Visual Studio Code Remote - SSH extension to connect to a remote machine running Docker engine. You can use the Remote - SSH and Dev Containers extensions together.
Top answer
1 of 11
28

I resolved this problem by switching to the remote server's Docker context on my local machine:

docker context create some-context-label --docker "host=ssh://user@remote_server_ip"

docker context use some-context-label

docker ps
# A list of remote containers on my local machine! It works!

After that:

  1. Connect via Remote-SSH to the container server
  2. Right click relevant container -> the "Attach Visual Studio Code"

That works for me.

(Note: One would think that I should be able to just use my local VSCode (skip step 1) to connect to said remote container after switching my local context, but VSCode complains Failed to connect. Is docker running? in the Docker control pane.)

2 of 11
8

This might sound very strange, but for me, I had to open a folder on the remote SSH server prior to using the Remote Containers extension in VS Code. If I didn't do that, then it would constantly try to find the docker service running locally, even though the terminal tab was connected to the remote SSH server.

This seems very weird, because if you're conncted via SSH in VS Code, then the extension should assume you're trying to attach to the container on the remote server. Shouldn't have to open a remote folder first.

By "opening a folder" on the remote server, the Remote Containers extension was then able to attach VS code to the container running on the remote SSH server. I didn't have to do any of the steps in any of those articles. Just simply use Remote SSH to connect VS Code remotely via SSH, open a folder, and then use Remote Containers.

🌐
Rancher Desktop
docs.rancherdesktop.io › vs code remote containers
VS Code Remote Containers | Rancher Desktop Docs
The [Visual Studio Code Remote - Containers] extension lets you use a Docker container as a full-featured development environment, which helps ensure a consistent environment across developer machines and makes it easy for new team members and contributors to get up and running.
🌐
Reddit
reddit.com › r/docker › difference between vscode's "remote - containers" and docker's "dev environments"?
r/docker on Reddit: Difference between VSCode's "Remote - Containers" and Docker's "Dev Environments"?
April 10, 2021 -

I'm new to all this. I want to create a containerized environment for each language to stay organized and learn Docker/Linux. What is the difference between the Remote Containers extension and the Dev Environments feature of Docker? Are they both using the same underlying Docker features to create an environment? Are both required for my purposes? What's the best practice for an environment container I probably won't ever need to share with anyone? Thanks!

Top answer
1 of 4
11
VSCode's remote-containers lets you connect to containers, either containers set up on another machine or set up locally. It makes it much easier to set up the networking so that you don't have to configure all the ports. If you're learning Docker, VSCode makes it so much easier. It has a few quirks, especially if you're running it on Windows with Docker Desktop/WSL2, but if you pair it with the Docker VSCode extension, it becomes incredibly easy to learn.
2 of 4
3
What I don't like about remote containers is that they cannot be used along with remote SSH. I have a remote host with a monorepo including multiple development containers. I want to be able to connect to the Remote SSH, and optionally from there, connect to the Remote Container. Instead the best option is to set the DOCKER_MACHINE IP to the remote SSH socket and connect directly to it with VSC Remote Container. But that means my VSC environment is in an isolated development container in the monorepo, rather than the host machine. I've considered moving the whole dev environment into the container, since that's basically what I do already in CI where I need to use "docker in docker" (dind). Then I would connect directly to that development container instead of the remote host. This way I wouldn't need to setup launch configs and port forwarding for each container in order to get debugging to work. So I think it might be a good option, but problem is then I lose out on any host-only features of the remote environment. I suppose I could open ssh on the host for connections from docker, and then use DOCKER_HOST to connect to the host in an SSH session from the container when I need to.
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › containers
Developing inside a Container
November 3, 2021 - Add your user to the docker group by using a terminal to run: sudo usermod -aG docker $USER · Sign out and back in again so your changes take effect. Install Visual Studio Code or Visual Studio Code Insiders. Install the Dev Containers extension. If you plan to work with other remote extensions in VS Code, you may choose to install the Remote Development extension pack.
🌐
GitHub
github.com › lab-sun › VScode-Tutorial
GitHub - lab-sun/VScode-Tutorial: [Use VSCode with Docker over SSH] · GitHub
In gerenal, we first configure SSH service in docker container and then use the VScode Remote-SSH Extension to connect to the docker container.
Starred by 4 users
Forked by 3 users
Languages   Dockerfile
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › overview
Advanced container configuration
November 3, 2021 - The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full ...
🌐
YouTube
youtube.com › syseng quick
Remote Development with Docker Devcontainers in VS Code - YouTube
A tutorial on using devcontainers with docker for development in VS Code.Project files can be found on GitHubhttps://github.com/sysengquick/devcontainers00:0...
Published   February 19, 2024
🌐
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › topics › education sector › educator developer blog
Using Visual Studio Code from a docker image locally or remotely via VS Online | Microsoft Community Hub
June 17, 2020 - You can run this container from VSCode locally see https://code.visualstudio.com/docs/remote/containers. ... Install and configure Docker for your operating system.
🌐
Docker
docker.com › blog › how-to-develop-inside-a-container-using-visual-studio-code-remote-containers
How to Develop Inside a Container Using Visual Studio Code Remote Containers | Docker
June 16, 2020 - The Remote Container extension uses Docker as the container runtime. There is also a Docker extension, called: Docker for Visual Studio Code. Brian gave a very good introduction at DockerCon LIVE 2020.
🌐
DigitalOcean
digitalocean.com › community › questions › vscode-remote-docker
VSCode remote Docker | DigitalOcean
October 24, 2024 - Open the Command Palette (Ctrl+Shift+P), then select Remote-Containers: Attach to Running Container. Now, in VSCode, open the Docker extension and select Connect to Host using the IP of your droplet with port 2376.
🌐
Lei Mao's Log Book
leimao.github.io › blog › VS-Code-Development-Remote-Host-Docker
VS Code Development Using Docker Containers on Remote Host - Lei Mao's Log Book
June 6, 2020 - By default, the VS Code Remote-Container uses local Docker host. This means that we are actually running the containers on the local computer. To use the container running on the remote host server, we have to add "docker.host":"your-user-n...
🌐
ASP.NET Hacker
asp.net-hacker.rocks › 2021 › 02 › 04 › remote-docker.html
Working inside a Docker container using Visual Studio Code
February 4, 2021 - The local VSCode will connect to the remote VSCode server and mirrors it in the user interface of your locally installed VSCode. It is like a remote session to the other machine but feels local.
🌐
Medium
medium.com › @minkesh.asati › development-with-the-docker-on-the-remote-server-via-ssh-from-vs-code-ef9e0f2fcbe6
VS Code + Remote Docker containers: Run docker of the remote server via SSH from VS Code | by minkesh asati | Medium
July 30, 2020 - In this post, I’ll walk you through the steps to set up the VS Code to do development with the docker that runs on the remote servers and connected via SSH from the VS Code that is installed on your local machine.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Dev Containers - Visual Studio Marketplace
Extension for Visual Studio Code - Open any folder or repository inside a Docker container and take advantage of Visual Studio Code's full feature set.
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › attach-container
Attach to a running container
November 3, 2021 - "extensions": ["dbaeumer.vscode-eslint"], // An array port numbers to forward "forwardPorts": [8000], // Container user VS Code should use when connecting "remoteUser": "vscode", // Set environment variables for VS Code and sub-processes "remoteEnv": { "MY_VARIABLE": "some-value" } }
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › tutorial
Dev Containers tutorial
November 3, 2021 - You can end your session in the container and go back to running VS Code locally with File > Close Remote Connection. This next section describes in more detail how the Dev Containers extension sets up and configures your containers. The Dev Containers extension uses the files in the .devcontainer folder, namely devcontainer.json, and an optional Dockerfile or docker-compose.yml, to create your dev containers.
🌐
Medium
medium.com › lseg-developer-community › how-to-use-the-visual-studio-code-remote-containers-extension-with-real-time-sdk-docker-image-4826f6f9e236
How to use the Visual Studio Code Remote — Containers extension with Real-Time SDK Docker Image | by Wasin Waeosri | LSEG Developer Community | Medium
March 7, 2023 - To close the remote connection, choose the “Close Remote Connection” from the drop-down menu. Now your VS Code and Dev container are ready to run the RTSDK Java example applications. All files and sub-folders are available in the VS Code explorer. If you open a terminal (Ctrl+` or Ctrl+Shift+` - Windows), the current location is /opt/refinitiv/Real-Time-SDK/Java folder too (You can navigate to other locations in the container as well) ... The refinitivapis/realtimesdk_java Docker image has built-in all RTSDK Java dependencies and build system, so you can run the SDK examples with the Gradle tool from the VS Code terminal.
🌐
Readthedocs
vscode-docs-arc.readthedocs.io › en › latest › containers › ssh
Connect to remote Docker over SSH - vscode-docs-arc
We recommend using the Visual Studio Code Remote-SSH extension to connect to a remote machine running Docker engine, but it also possible to connect to the remote Docker engine directly, using SSH tunneling.