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