Running host apps within toolbox environment possible? | SilverBlue | Toolbox VS Code

I frequently need to set up different environments for programming projects. Mainly different versions of Java and some C++. What I generally do is create a toolbox container, install whatever Java version I need, the install VSCode and run everything from inside the container.

What I would like to do is layer VSCode through rpm-ostree and not have to install it in each container over and over. My problem is that if I layer VSCode, it won’t pick up anything inside a container. Then, if I enter the container and type “code” from there, it says the command doesn’t exist.

Is there some way to run VSCode as a layered installation on the host from inside a container so it picks up the container environment where I have Java or GCC or whatever installed?

Added container

Added docker, podman

Hey there, I don’t have that workflow because I do not use VSCode, but If I had a situation where I needed environments for development (Rust, Go, Python etc. . .) I would simply build an image with all the tools I needed and re-use it as much as I needed.

So basically, use a Podman/Dockerfile image of fedora:latest and install VSCode and whatever other tools you need to get it started. Then you can use that image in toolbox over and over. . .

So here is an example of what I did with anaconda-navigator running in it’s own /home dir so I can keep those dependencies in their own place (also no need to alter .bashrc etc.) :

I am sure there are better ways of achieving this and there are more capable people here who will chime in with their solutions.


Just to add here are some more ideas for you :

1 Like

Thank you so much. I will look into all of these. I’m sure I’ll find one of them works for what I need.

1 Like

I’m sure more folks will comment on better approaches so play around with these while some more suggestions come in.

Hello @fooze666 ,
I do some java work and often just use Quarkus to spin up an app skeleton then run the containerized app in dev mode through quarkus to make live changes to code an see immediate updates on the app, quite cool. That’s for my reactive java programming.
Also use netbeans frequently, it can start containers from within, but right now mine is set up for db serving.
And I also am finding that Podman Desktop is the way to go for what you are wanting, it runs in admin or dev mode and has all the cool container tools available through copious plugins. Plus there is an AI playground and did I mention Openshift Local, Kubernetes, bootable container images?

1 Like

Thank you for the suggestions. It’s starting to look like the VSCode remote development extension and Podman are what I’m looking for. I’m going to do a bit of experimenting and see what I can come up with.

2 Likes

Thank you both for pointing me in the right direction. It was a big help and I managed to get it working perfectly.

For the sake of anyone reading this in the future, here is what I did (Silverblue 40):

Create a repo file for VSCode using sudo and nano or vim or whatever you like:

/etc/yum.repos.d/vstudio_code.repo

The file should contain the following:

[code]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

The “[code]” is not a typo, it should be in the file.

This will enable the VScode repo and you can then layer VScode on your Silverblue image:

rpm-ostree install code

Open the ide, go to the extensions market place and install DevContainer and Remote Containers extensions. Open settings for the Devcontainer extension and change the “Docker Command” from ‘docker’ to ‘podman’ if you want to use podman.

Use the explorer view to open a project you want to develop in a container or create a new project folder. In that folder create a directory named “.devcontainer”. In the .devcontainer directory create a file called devcontainer.json

In the devcontainer.json file:

{
	"name": "Fedora Dev Container",
	// Pull latest available Fedora docker image
	"image": "fedora:latest",
	// Set container workspace directory
	"workspaceFolder": "/workspace",
	// Bind local workspace to container workspace
	"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,Z",
	// Install git, github cli, java 17
	"postCreateCommand": "dnf install -y git java-17-openjdk java-17-openjdk-devel gh"
  }

VSCode should detect the container file and ask you if you want to reopen the project in a container. Say yes, obvsiously. If you miss the dialog, you can also open the command pallete, search for devcontainer, and select “rebuild and open in container”.

It will take a few minutes the first time for everything to download and install, but after that getting into the project takes just a few seconds. It will automatically start the container when you are working with the project and stop it when you’re not. It will also prompt you to install any extensions in the container that might be needed such as the intellisense, java debugging, tabnine, etc.

You can also install podman desktop to make managing multiple containers a little easier.

My example above pulls the latest Fedora image and installs git and java. You can change the command to install whatever you want or even create a bash script file to execute more complex setup options and call that instead.

If you need to change configurations or Fedora versions, you can just edit the devcontainer.json file and then run the rebuild and open command to update the environment, leaving your project and code intact.

I hope this helps somebody somewhere. :slight_smile:

3 Likes

This is definitely cool of you to do ! Thanks for this, it will help others. :fedora:

1 Like

Added howto

If somebody wants to do a nice writeup of these steps, it would very likely help more people!

As the howto tag may be intended to be used for guides, where you dont need to read an entire thread to get the info.

(It is loose though and not decided yet)

Added howto-candidate and removed howto

I already have. . . Waiting for the other Dominos to fall

1 Like