Jonathan
Jonathan

Reputation: 1347

VS Code "Attach Visual Studio Code" to remote container error

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?

Upvotes: 3

Views: 8918

Answers (3)

mherzog
mherzog

Reputation: 1230

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

Upvotes: 0

Shubham Vishwakarma
Shubham Vishwakarma

Reputation: 136

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.

Upvotes: 0

The Fool
The Fool

Reputation: 20420

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.

Upvotes: 3

Related Questions