Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode dev container - attach to existing container when opening vscode

I am using a dev container to develop my c++ project on a microcontroller. The have my entire toolchain in a docker-compose / dockerfile, which autorestarts.

I have to follow these steps every time:

  • open vscode
  • open palette
  • dev containers: attach to running container
  • select my dev container

A second vscode will open, which connects to the docker container.

I always start vscode from a terminal:

  • cd to repo
  • code .

Is there a way to make vscode remember that I always want to connect to my dev container when vscode is openened in that specific repo?

I am reading stuff on devcontainer.json, but I can't figure out how to define it so that i just opens an already existing container.

enter image description here

like image 300
bas Avatar asked Nov 28 '25 13:11

bas


1 Answers

You can use devcontainer CLI to open the devcontainer directly. I found the solution here: bh231's answer

You can install it directly in VS Code and then you need to add the devcontainer CLI path to your $PATH variable. After terminal restart you can go to your repo folder (as you did before) but then you need to call devcontainer open which will open your devcontainer directly from there.

like image 157
burn4science Avatar answered Nov 30 '25 05:11

burn4science



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!