Trying to get vscode to attach to running container made with boxbuddy/distrobox -- docker doesn't see my containers at all

Hi,

Having problems with vscode connecting to container with new new install, here is what I did:

Fresh install of bluefin-dx:gts 39

Ran a few of the ujust commands… setup shell with zsh, installed brew and atuin, ran ujust dx-group

I created a new container with BoxBuddy/Distobox,

Open vscode and try Attach to running container... and I get an error message saying “There are no running containers to attach to.”

Check distrobox, podman, and docker:

❯ distrobox list
ID           | NAME                 | STATUS             | IMAGE                         
4cd3550bdc77 | testcontainer1        | Up 12 minutes      | quay.io/toolbx/ubuntu-toolbox:latest

❯ podman ps -a
CONTAINER ID  IMAGE                                 COMMAND               CREATED            STATUS         PORTS       NAMES
4cd3550bdc77  quay.io/toolbx/ubuntu-toolbox:latest  --verbose --name ...  About an hour ago  Up 12 minutes              testcontainer1

❯ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Docker should pick up my distrobox containers right? Did I miss something? I was pretty sure this was going to work just out of the box basically.

I havn’t run ujust bluefin-cli… am I supposed to? A little bit unsure what bluefin-cli is for and when I should be using that vs host shell

Any help appreciated, thanks

You don’t need bluefin-cli, it’s not for development in your IDE it’s for terminal tool, etc.

By default your distrobox containers are running under your user podman.

Docker runs at a system level and is a completely different engine from podman. A distrobox created by docker is running as root unlike the podman version which runs as your user.

By default we have vscode setup to work with devcontainers using the default backend of docker. This would behave exactly the same as if you were on a Mac or Windows. If you wish to have your distrobox containers work with vscode instead, there is a script called podman-host that you can set your docker path to for your devcontainers extension.

2 Likes

Distroboxes are for pet containers not development. If you click on this thing at the bottom of vscode:

image

and then select “New devcontainer”, then type “ubuntu” in the search box:

Hit enter (and I think there’s a confirmation enter in there too) will get you an ubuntu container.

2 Likes

the script podman-host is aimed at working with flatpak-vscode, not layered-vscode. It might work the first time, and then alters the DevContainers own workflow of folder, files creation and symlinking. The script needs revision and being rewritten for Silverblue and its derivatives. I have tested it for Silverblue-40 and Bluefin-DX-39. podman-host will also conflict when the user wants to create a new DevContainer.

The repeatable and reproducible way of integrating Distroboxes with vscode is by declaring the distrobox of choice in its own .json configuration file. See summary at the bottom.

The Silverblue community needs to work on a unified script that makes a seamless integration with layered-vscode. That script should allow the user to interact with Docker, Podman, Toolbox, Distrobox, and DevContainers from vscode.

The integration problem of vscode with containers is not restricted to Universal Blue but to all Silverblue and its derivatives. I have found the same issues in a fresh Silverblue-40 installation as well as in a fresh Bluefin-DX-39. Work of the past two weeks.

The DevContainer developers have not had in mind atomic Linux distributions such as Silverblue. A case in point: Vscode integrates without much trouble to Distrobox and DevContainers in Ubuntu 22.04. But this operating system is not atomic and follows conventional rules.

I will try to make a procedure available for manual integration of a fresh layered-vscode installation with Distrobox containers. I understand that Distroboxes aim is at being pet containers but as such will need to run sometimes code or scripts that need to be modified and tested under the container conditions. That’s when the vscode integration comes in handy.

Summary of Distrobox integration to vscode

  1. Take note of the name of the distrobox. You will need it to create its .json configuration file. For the sake of the example, let’s say the distrobox name is conky-nvidia.

  2. Create the folder nameConfigs with

mkdir ${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs
  1. Create a .json file with the same name as your distrobox. Example: conky-nvidia.json
touch  ${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs/conky-nvidia.json
  1. Edit the created file and add this snippet:
  {
     "remoteUser": "${localEnv:USER}",
     "settings": {
        "dev.containers.copyGitConfig": false,
        "dev.containers.gitCredentialHelperConfigLocation": "none"
      }
   }
4 Likes

Thanks @f0nzie and @m2Giles for clarifying how this works. Ive been struggling to figure out how to get DevContainers to work with Vscode since I switched to Bluefin. I must have ran that podman-host script when I was first testing things out. Works great now that I’m using the Docker backend.

Thank you for this!
I attempted to make the nameConfig JSON file, with the name of my distrobox, but get a “could not connect to gpg agent on local host (/run/user/1000/gnupg/S.gpg-agent.extra). Make sure the service is running” error when I try to connect VSCode to the distrobox container. Is there an additional step I’m missing?

I have seen that error before. It might be related to permissions, sometimes when DevContainer cannot create a file or folder where it is supposed to do.

Let’s do some health checks:

  1. Is Docker running as user (rootless)?
  2. Can you pass this test docker run hello-world, without errors?
  3. Do you have a .vscode folder under ${HOME} ? If yes, ten delete it.
  4. Do you have other docker, or podman, or distrobox images under ${HOME/.local/share/containers/storage?
  5. Could you check if there is a uid and gid that doesn’t correspond to that folder?
  6. What is your container engine under “DevContainer-Docker Path” in Settings?
  7. When you try building a stock DevContainer, does it build without errors?

Uhhh - devs have more pet comtainers than anyone else …

The idea is to gain economies of scale by sharing OCI layers across versions of tool chains.

Why else did you build bluefin-dx ?

If this is an anti-pattern - just why is it the recommended developer experience ?

I do like devcontainers. But …

1 Like

I finally took the time to work through getting vscode to open a remote connection to a running distrobox container. While not technically a devcontainer, the result seems to be similar.

Here is what I discovered so far.

Enjoy!

bluefin - use podman distrobox container in vscode

To use a bluefin distrobox in vscode as a devcontainer, do the following to create and attach to a running podman distrobox.

However, there are some pretty severe limitations to doing this. But it does work.

TL;DR - you will be better off to:

  • use docker to create distrobox(es) to which you may want to attach from vscode;
  • use docker as normal to create vscode per-project devcontainers

Please read on.

steps

  • Create distrobox - see [[#fedora41-distrobox-quadlet]] below
  • Setup vscode to use podman instead of docker - User/settings.json: "dev.containers.dockerPath": "podman" - only works as User setting
  • Use Dev Containers: Attach to Running Container… and select [[#fedora41-distrobox-quadlet]]
  • Once inside use Dev Containers: Open Container Configuration File
  • Edit to look like this – needed to workaround some of the podman differences:
{
	"workspaceFolder": "/var/home/klmcw/src/soft.lan/klmcw/budget-trans-adapter",
	"runArgs": [
		"--userns=keep-id"
	],
	"containerEnv": {
		"HOME": "/var/home/klmcw"
	},
	"remoteUser": "klmcw",
	// Note these must be installed manually one time; they are tracked here
	"extensions": [
		"alexcvzz.vscode-sqlite",
		"ms-azuretools.vscode-docker",
		"ms-python.autopep8",
		"ms-python.isort",
		"ms-python.python",
		"streetsidesoftware.code-spell-checker",
		"tamasfe.even-better-toml"
	],
	"settings": {
		"[python]": {
			"editor.formatOnSave": true,
			"editor.codeActionsOnSave": {
				"source.fixAll": "explicit",
				"source.organizeImports": "explicit"
			},
			"editor.defaultFormatter": "ms-python.autopep8"
		},
		"python.terminal.activateEnvironment": true,
		"terminal.integrated.defaultProfile.linux": "bash",
		"docker.dockerPath": "podman"
	}
}
  • Install extensions one time - they will be tracked in the container settings (see above sample).

podman limitations

While it is theoretically possible to use docker instead of podman with distrobox, it seemed simpler to just get vscode to connect to a running (working) podman container.
See https://code.visualstudio.com/remote/advancedcontainers/docker-options#_podman

Attach to Running Container limitations

You only get one remote connection per container across all vscode instances running. You must disconnect from the container in the instance of vscode where it is connected; only then can you connect to it from a different vscode instance.

Even if you can use the “Attach in Current Window” from the context menu in Remote Explorer, it will open the connection with whatever folder from which you connected first.

So you it seems you cannot have separate connections for different dev projects. This is a downside. Please be aware.

fedora41-distrobox-quadlet

Please note the ublue-os/toolboxes repo. I am using the fedora-toolbox.

This is a snippet from the distrobox.ini I am using that focuses on the vscode prerequisites.

[fedora41-distrobox-quadlet]
additional_packages=git
image=ghcr.io/ublue-os/fedora-toolbox:latest
init=false
init_hooks=sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
init_hooks=echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/vscode.repo > /dev/null
init_hooks=sudo dnf update -y
init_hooks=sudo dnf install -y code
root=false
replace=true
start_now=false

References

1.https://code.visualstudio.com/docs/devcontainers/attach-container
2. https://code.visualstudio.com/docs/devcontainers/containers#_container-specific-settings
3. https://code.visualstudio.com/api/advanced-topics/remote-extensions#debugging-in-a-custom-development-container
4. https://code.visualstudio.com/remote/advancedcontainers/docker-options#_podman
5. https://github.com/ublue-os/toolboxes
6. https://github.com/ublue-os/toolboxes?tab=readme-ov-file#quadlets

1 Like