3

I am trying to develop in a remote container.

I run VS Code on my local windows machine. I have a linux machine which runs docker and a bunch of containers.

I have the "Remote - Containers" and "Remote - SSH" extensions installed in VS Code.

I can connect to my linux machine in VS Code and I can see the running containers.

I can right click on a container and choose "Attach Shell". This works fine: enter image description here

When I right click on a container and choose "Attach Visual Studio Code" I get an error:

enter image description here

UPDATE

The above error was raised because (for some reason?) docker must be running locally on windows also even though we are fully on a remote machine. I've installed and run docker locally.

Now when I right click on a running container, I get a different error:

enter image description here

Of course the containers are running -- I see them.

How can I Attach Visual Studio Code to a running remote container successfully?

3 Answers 3

3

This may not be a real answer but it's too much for a comment.

I believe you have a local machine and docker on a remote server.

The first thing you have to do is to install docker on your local machine and configure it so that's its looking for the docker host on your remote server.

Then you can create a .devcontainer.json on your machine. If you have the extension installed, VSCode will offer you do open this as container environment. Since your docker host sits on remote, this will now happen on your server instead of your local machine.

When I did the setup, I followed amongst other things this guide. Especially the SSH-Agent was required to get a remote docker host working. https://code.visualstudio.com/docs/remote/containers-advanced#_a-basic-remote-example

Here is a example .devcontainer file of mine.

Now back to your initial question, I don't think you will be able to use the remote container extension on a container that wasn't started as dev container. This is because vscode will install a bunch of stuff in there when its first set up. Similar to the SSH Extension. I may be wrong on this so take it with a grain of salt.

It may also be worth noting that once you connect to your server via SSH and have then the regular docker extension (which is not the remote container extension) installed, on remote, you will see your docker images listed there. But that does not mean you will be able to connect like that from local to remote container. For that you need to configure a docker remote host.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I can now run VS Code and develop in a container locally. I can start any container locally and right click on it and "Attach VS Code" works on the local container. It does not give me the option to do this on a remote container. In fact, Remote-Containers doesn't seem to be installed in the remote machine (just locally) and I can't figure out how to force. I uninstalled and reinstalled. No luck. I really don't want to make a .devcontainer. I just want to attach to an existing container. I've given up for now and am back to emacs.
See your issue is that you are trying to do some inception move. You are not supposed to SSH into remote and then Use the container extension. What you want to do is to install docket locally and configure it to use a remote host. Then you just use your local Vs code docker extension. It will use the remote host so you can work on remote container.
0

I have also faced similar issue after doing some research I found the issue was with my installation.

But I faced this issue when I installed vs-code through snap in Ubuntu.

May be try uninstalling VS Code and reinstalling it.

It should work if Docker is installed properly.

Comments

0

For me, I just reloaded the VSCode window. I then could right click on the container and attach to it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.