Jorge Arévalo
Jorge Arévalo

Reputation: 3008

How to detach VSCode from a running container?

This is probably the most stupid question ever, but I can't find an easy way to do it.

I successfully attached VSCode to a running container in my machine. But now, each time I open VSCode, it's automatically attached to that container. Is there any way to detach it and just open VSCode?

EDIT: As you can see, each time I open VSCode insiders, it's automatically attached to a running container. It even starts the container if it's stopped

enter image description here

This is the menu I see when I try to run commands associated to remote-containers. I'm attached to a running docker container and cannot reopen the folder without being attached to that container.

No reopen folder unattached to running container

Yes, I'm using Remote Development Extension Pack + VSCode Insiders 1.35

These are the versions of VSCode Remote, Node and other relevant software components on my machine

enter image description here

So, how could I just detach VSCode insider from that container without deleting the container + the image?

Upvotes: 9

Views: 18684

Answers (4)

umitkilic
umitkilic

Reputation: 355

For Linux,

right click on vscode icon -> New Empty Window

Then go to Docker extension (if you deal with docker, I assume you have it in vscode). You will see it in containers section. Right click -> stop and then right click -> remove. Also you might have to remove from the images section the related image.

This worked for me.

Upvotes: 0

Gul Saeed Khattak
Gul Saeed Khattak

Reputation: 209

What you are lookinf for is most probably a way to disconnect VSCODE from the remote container. Click on File in your VSCODE and select 'close remote connection' from the drop down .

Upvotes: 4

Magnus Melwin
Magnus Melwin

Reputation: 1517

The way to do this is by closing the workspace folder - that will detach the running container completely and close the existing project.

The next step would be to reopen the local source code folder. There is folder call .devcontainer - which contains a devcontainer.json file -

// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.122.1/containers/ubuntu
{
    "name": "Ubuntu",
    "build": {
        "dockerfile": "Dockerfile",
        // Update 'VARIANT' to pick an Ubuntu version. Rebuild the container 
        // if it already exists to update. Available variants: 18.04, 20.04
        "args": { "VARIANT": "18.04" }
    },

    // Set *default* container specific settings.json values on container create.
    "settings": { 
        "terminal.integrated.shell.linux": "/bin/bash"
    },

    // Add the IDs of extensions you want installed when the container is created.
    "extensions": []

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "uname -a",

    // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
    // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

    // Uncomment when using a ptrace-based debugger like C++, Go, and Rust
    // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

    // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
    // "remoteUser": "vscode"
}

Deleting this will also detach a running container - you can even modify the docker container to the one you desire and rebuild it again.

Upvotes: 0

makons
makons

Reputation: 612

Maybe the command Remote-Containers: Reopen Folder Locally is what your looking for.

Upvotes: 9

Related Questions