Post

Setup Devcontainer in VSCode Flatpak with Podman

Set up a Devcontainer in VSCode using Flatpak and Podman for a seamless development experience.

vscode + flatpak + devcontainer + podman

Want to use DevContainers with VS Code Flatpak and Podman? It’s not as straightforward as it sounds. Flatpak’s sandboxing and Podman’s socket access pose challenges. This post will guide you through the hurdles, offering solutions and workarounds to get your DevContainer up and running smoothly. We’ll cover essential configurations, troubleshooting tips, and best practices to make your development experience as painless as possible.

Prerequisites: podman, flatpak

  • Install flatpak vscode and podman
    1
    2
    3
    
    flatpak install -y \
    com.visualstudio.code \
    com.visualstudio.code.tool.podman
    
  • Start podman socket
    1
    2
    
    systemctl --user enable --now podman.socket && \
    systemctl --user status podman.socket
    
  • We need to override some vscode flatpak settings
    1
    2
    3
    4
    
    flatpak override --user \
    --filesystem=xdg-run/podman:ro \
    --filesystem=/run/user/$UID/podman/podman.sock:ro \
    com.visualstudio.code
    
  • Test podman socket connection
    1
    2
    3
    4
    
    curl -w "\n" \
    -H "Content-Type: application/json" \
    --unix-socket /run/user/$UID/podman/podman.sock \
    http://localhost/_ping
    

    You should see OK if everything is alright.

  • install devcontainers extension
    1
    2
    
    flatpak run --command=sh com.visualstudio.code -c \
    "/app/extra/vscode/bin/code --install-extension ms-vscode-remote.remote-containers"
    
  • We need to replace docker with podman (podman-remote that connect with host podman). We can do that by opening vscode and go to user setting ctrl + ,. and search for dev.containers.dockerPath change the setting from docker to /app/tools/podman/bin/podman/podman-remote. And search for dev.containers.dockerSocketPath change it to /run/user/$UID/podman/podman.sock. Replace $UID with yours.

To open and edit this file with your favorite text editor (e.g., code, micro, vim, or gedit): Or from terminal

1
2
mkdir -p ~/.var/app/com.visualstudio.code/config/Code/User
nano ~/.var/app/com.visualstudio.code/config/Code/User/settings.json

and put the setting

1
2
3
4
{
    "dev.containers.dockerPath": "/app/tools/podman/bin/podman-remote",
    "dev.containers.dockerSocketPath": "/run/user/$UID/podman/podman.sock"
}

replace $UID with yours. Find with id -u

  • Test if vscode flatpak is connected and working with podman (optional)
    1
    2
    
    flatpak run --command=sh com.visualstudio.code -c \
    "/app/tools/podman/bin/podman-remote version"
    

Check out How I Built a Dev Container Workflow with Flatpak VSCode, Devcontainer and Podman on Wayland for more about Vscode devcontainer running gui.

This post is licensed under CC BY 4.0 by the author.