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:
- Connect via Remote-SSH to the container server
- 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.)
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:
- Connect via Remote-SSH to the container server
- 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.)
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.
Connecting to a remote container on a remote host?
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.comvisual studio code - Dependencies to connect to a remote docker container in VSCode? - Stack Overflow
How to set up development in remote Docker container?
Videos
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?
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:
- Install docker and ssh client
- Add your user to docker group
- Install VSCode
- Configure Server
- (After server config below): edit
~/.config/Code/User/settings.jsonwith
"docker.host":"tcp://localhost:23750",
- Configure your ssh keys for the
Server - (After every reboot run on terminal:
ssh -N -L localhost:23750:/var/run/docker.sock <user>@<serveraddr>) - Run VSCode and install
Remote Developmentextension. Restart VSCode - Now you should see your running containers in VSCode
Remote explorer>Containers> Other Containers
Server:
- Install docker and ssh server
- Install VSCode (this may not be a requirement on the server)
- Add your user to docker group and start your container
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.
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 :)