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?