Quick distrobox for R-4.4.0 (tidyverse) + DevContainer vscode integration

This is for someone with Silverblue 40, interested in a quick addition of an R-4.4.0 distrobox with Tidyverse included, plus the possibility of casual development and testing of Rscripts via VSCode:

R-4.4.0 installation

  1. From a terminal run this:
distrobox-create --name R-4.4.0 --image ghcr.io/rocker-org/devcontainer/tidyverse:4.4

Downloading and creating the image will take about 5 minutes.

  1. Enter the distrobox and upgrade
distrobox enter R-4.4.0
sudo apt update
sudo apt upgrade -y
  1. Export binaries:
distrobox-export --bin /usr/local/bin/R
distrobox-export --bin /usr/local/bin/Rscript

The benefit of these two export is that you will be able to execute R code from the host. Additionally, if you attempt to install any vscode R extension, it will not error.

Integrate the R-4.4.0 distrobox with vscode

Assuming you already have installed the DevContainer extension, (ii) have Docker in working order; (iii) podman works from the command line.

  1. Open vscode. Go to Settings. Search for “Docker path”. You will see the Docker and DevContainer extension showing their corresponding “Docker Paths”. On the DevContainer side, change whatever the value is there. It could be empty or filled with “docker”.

  2. Change the value to “podman”. Close Settings

  3. Ensure your R-4.4.0 distrobox is opened and active. Otherwise, it will not be seen by vscode.

  4. Go to vscode, press F1 for the command palette. Search for “Attach to Running Container
    image

  5. The R-4.4.0 container will pop up. Select it and press Enter.
    image

  6. If you are lucky, you will get no error and be able to login to the container as ${USER}. But most likely, as per my experience, you will get an error of “Access Denied”. This is because you attempted to access a distrobox before via vscode but without a configuration file. We will diagnose and fix this in the next steps.

  7. List the folder and files under the ~/.vscode-server/ folder. This is the folder where the DevContainer extension will want to write its configuration files for the distrobox.

ls -la /var/home/${USER}/.vscode-server/

If you see a bunch of folders and files with an owner and group that is a number, and not your username, it means you will be denied access when trying to create a DevContainer.

  1. Delete the folder with that unknown uid and gid with:
sudo rm -rf ~/.vscode-server

You realize we are using sudo because those child folders and files are not owned by the default user. Because vscode doesn’t know how to treat the R-4.4.0 distrobox -there is no configuration file for it, it assigns any random uid and gid. We will fix this in the next steps.

  1. Confirm you don’t have a folder nameConfigs already. If yours is an untouched vscode/distrobox installation, you will not have that folder.
ls -al ${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs

You should get the error “No such file or directory”. That is okay.
Now, create the directory with:

mkdir -p ${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs
  1. Create a .json file with the exact name of your distrobox, for our example, it is “R-4.4.0.json”:
nano  ${HOME}/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs/R-4.4.0.json

Copy paste this code into the file and save it:

{
  "remoteUser": "${localEnv:USER}",
  "settings": {
    "dev.containers.copyGitConfig": false,
    "dev.containers.gitCredentialHelperConfigLocation": "none"
  }
}

EPILOG

This is the final solution to all our troubles with the integration of Distrobox and vscode. We will not get files or folders owned by a random uid or gid. Proceed in the same manner with other distroboxes whenever you want to quick run and test any script.

The intention of accessing a Distrobox from vscode is not aimed at development. It is much easier, productive, and reproducible to do development with DevContainers.

1 Like

Removed server

Added distrobox