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 code will not work.
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.

Discussions

Connecting to a remote container on a remote host?
Probably you could workaround this by running an ssh server in the container, port forwarding and connecting directly via the Remote SSH extension? More on reddit.com
🌐 r/vscode
9
10
September 14, 2022
visual studio code - Dependencies to connect to a remote docker container in VSCode? - Stack Overflow
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 follo... More on stackoverflow.com
🌐 stackoverflow.com
How to use VScode in a container in a remote machine?

Likely you are after https://GitHub.com/coder/coder or https://GitHub.com/coder/code-server

More on reddit.com
🌐 r/docker
16
0
December 16, 2022
How to set up development in remote Docker container?
https://code.visualstudio.com/docs/remote/containers-advanced#_developing-inside-a-container-on-a-remote-docker-host More on reddit.com
🌐 r/vscode
6
13
July 30, 2019
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › ssh
Connect to remote Docker over SSH
November 3, 2021 - Make sure the remote machine host key is already memorized in the known_hosts file. The simplest way to ensure this is to connect to the machine via ssh client program (run ssh username@host:port from the command line).
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › containers
Developing inside a Container
November 3, 2021 - After the build completes, VS Code will automatically connect to the container. You can now interact with your project in VS Code just as you could when opening the project locally.
🌐
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. ... FROM mcr.microsoft.com/dotnet/sdk:5.0 COPY . /app WORKDIR /app EXPOSE 5000 5001 # ENTRYPOINT ["dotnet", "run"] not needed to just work in the container · If you don't have the docker tool installed, VSCode will ask you to install it as soon you have the dockerfile open.
🌐
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" } }
🌐
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 - This file confirm the python requirements and VSCode Extensions which are to be installed. A devcontainer.json file is similar to launch.json for debugging, but designed to launch (or attach to) a development container instead. At its simplest, all you need is a .devcontainer/devcontainer.json file in your project that references an image, Dockerfile, or docker-compose.yml, and a few properties.
Find elsewhere
🌐
Reddit
reddit.com › r/vscode › connecting to a remote container on a remote host?
r/vscode on Reddit: Connecting to a remote container on a remote host?
September 14, 2022 -

Remote Containers are a very interesting feature, but so far I haven't found any mention in the docs that it is possible to connect to a container that actually runs on another machine.

Is this possible/planned or do you have to have the containers always locally?

🌐
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 feature set. A devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack.
🌐
Rancher Desktop
docs.rancherdesktop.io › vs code remote containers
VS Code Remote Containers | Rancher Desktop Docs
Install and launch Rancher Desktop. Select dockerd (moby) as the Container Runtime from the Kubernetes Settings menu. Install and launch Visual Studio Code or Visual Studio Code Insiders. This tutorial uses Visual Studio Code. Install the Remote Development extension pack.
🌐
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 - From the Extensions tab of VS Code, install Docker. ... On the right side of the settings.json file, click on the icon (see the below image). ... Type docker.host in the settings search bar.
🌐
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.
🌐
GitHub
github.com › lab-sun › VScode-Tutorial
GitHub - lab-sun/VScode-Tutorial: [Use VSCode with Docker over SSH] · GitHub
(Skip this step, if your Dockerfile contains RUN echo 'root:your_password' | chpasswd) Now we have finished the configuration of the SSH service in container. Open VScode as a New Window. Then, click the Extensions.
Starred by 4 users
Forked by 3 users
Languages   Dockerfile
🌐
Reddit
reddit.com › r/docker › how to use vscode in a container in a remote machine?
r/docker on Reddit: How to use VScode in a container in a remote machine?
December 16, 2022 - Sorry for not giving context, I clicked twice the button by pure dumbness. ... Log into the remote machine with SSH from VScode and once done install docker remote extension on that remote box.
🌐
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 - 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-name-on-host@hostname" to VS Code settings.json.
🌐
Reddit
reddit.com › r/vscode › how to set up development in remote docker container?
r/vscode on Reddit: How to set up development in remote Docker container?
July 30, 2019 -

Hi fellow redditors

I am struggling with how to set up VS Code for remote development using the new remote-suite of plugins — I hope that you will be able to give me some help or provide links to relevant blog posts, example projects and the like.

Ideally, I would like to be able to work with remote files and my remote dockerized Python-environment, as if I was developing locally... or at least get as close as possible :)

Current setup

Local machine:

  • Running Windows 10, and I have limited administrative rights.

  • VS Code with remote extensions is installed, Docker currently is not. I can use ssh from the Windows Terminal (cmd).

Remote machine:

  • Powerful desktop/server running Ubuntu Linux I have administrator priveleges.

  • I use it for machine learning tasks, and currently interact with it through ssh/terminal as well as Jupyter Lab running inside a Docker container.

  • I am allowed to edit the Dockerfile if needed.

  • My code and data is located on the Linux filesystem, which is mapped/mounted into the Docker containers file system.

  • Editing of files is done by using Cyberduck, which enables editing of remote files.

  • Debugging and code execution are done in a Jupyterlab notebook or in a terminal inside the running Docker Container.

Any help is greatly appreciated :)

🌐
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.
🌐
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.
🌐
GitHub
github.com › microsoft › vscode-remote-release › issues › 4396
Remote-Containers plugin cannot connect to Docker running in remote host properly. · Issue #4396 · microsoft/vscode-remote-release
January 29, 2021 - VSCode Version: 1.52.1 Local OS Version: Windows 10 Remote OS Version: CentOS 7.6 Remote Extension/Connection Type: SSH Steps to Reproduce: Connect to remote CentOS host Install the Remote-Containers plugin and start it globally. Start a...
Author   KarKLi