Using VSCode Flatpak to launch DevContainers Using Podman with Support for Nvidia CUDA and VSCode's "Container Features" In SilverBlue.
Note: This Setup Works for Machine Learning and GPU Acceleration in Containers
Install Visual Studio Code and a Podman tool
➜ ~ flatpak --user install flathub com.visualstudio.code
*Required for Container Build.
flatpak override --user --filesystem=/tmp com.visualstudio.code
*Required for CUDA Support.
sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml
sudo chmod a+r /etc/cdi/nvidia.yaml
Being in a Flatpak, we will need access to host's podman
(or docker
) to be
able to use the containers. Place this in your ~/.local/bin/podman-host
#!/bin/bash
# Privileged and Security-Opt Disable are needed for SELinux
# to allow Workspace Read-Write Permission and Building DevContainer Features.
set -x
if [ "$1" == "exec" ]; then
# Remove 'exec' from $@
shift
script='
result_command="podman exec"
for i in $(printenv | grep "=" | grep -Ev " |\"" |
grep -Ev "^(HOST|HOSTNAME|HOME|PATH|SHELL|USER|_)"); do
result_command=$result_command --env="$i"
done
exec ${result_command} "$@"
'
exec flatpak-spawn --host sh -c "$script" - "$@"
elif [[ "$1" == "run"* ]]; then
# Remove 'run' from $@
shift
#exec flatpak-spawn --host podman run --privileged "$@"
exec flatpak-spawn --host podman run --runtime crun --hooks-dir "" --device nvidia.com/gpu=all --privileged "$@"
elif [[ "$1" == "start"* ]]; then
# Remove 'start' from $@
shift
exec flatpak-spawn --host podman start --runtime crun --hooks-dir "" "$@"
elif [[ "$1" == "buildx" && "$2" == "build" ]]; then
# Remove 'buildx build' from $@
shift 2
exec flatpak-spawn --host podman build --security-opt label=disable "$@"
else
exec flatpak-spawn --host podman "$@"
fi
and make it executable: chmod +x ~/.local/bin/podman-host
.
Open VSCode settings (Ctrl+,) and head to Remote>Containers>Docker Path
and
set it to the path of podman-exec
, like in the example
This will give a way to execute host's container manager from within the flatpak app.
Place this in your ~/.config/containers/registries.conf
unqualified-search-registries = [ "docker.io", "quay.io", "registry.fedoraproject.org", "registry.access.redhat.com"]
short-name-mode="disabled"
Your devcontainers configurations should work out of the box without any modification now!
For some official VSCode devcontainers, you may need to append additional config.
{
"remoteUser": "root",
"containerUser": "vscode",
}
Here is a fully functional devcontainer example. It includes USB-Passthrough, GPU-Passthrough, X11 Integration, VNC Integration and set of extensions for Embedded Development.
...