VS Code Intellisense Inside an Apptainer Container

Create a full functioning modular development environment with Apptainer or Singularity

Davis Catherman
3 min readFeb 21, 2022
apptainer.org and code.visualstudio.com

This tutorial will walk through having software/libraries in an Apptainer container (formerly known as Singularity) and then connecting to the container using VS Code which will allow all the benefits of Intellisense as if the libraries are installed directly onto your system for any programming language.

Note: If you would like any additional tutorials on pieces of this process, please ask in the comments below! Be sure to give me a follow for more tutorials like this in the future.

To get started, you will need the following:

  1. Apptainer (or Singularity) installed on your system. Note that for Singularity, replace anywhere I write apptainer with singularity and it should all work fine.
  2. A built container with the libraries you want Intellisense to reference. I will be using my own definition file: github.com/…/argos_base.def
  3. VS Code installed on your local system. You may get it here code.visualstudio.com/download
  4. A local folder with code that will reference the libraries. In my case, a simple set of .cpp & .h files (mine are included below).
  5. A little bit of time.

If you want to build my container, use the following commands in a terminal:

bash commands to download and build an example container

Lets begin! First, I will assume your container and files are inside a test_proj folder on your home directory like so:

test_proj/ 
|-- argos_base.sif
`-- code
|-- proj_loop_functions.cpp (source code below)
`-- proj_loop_functions.h (source code below)

1 directory, 3 files

Make a file ~/.ssh/config if one does not exist and add the following lines (replace the path and username as needed):

~/.ssh/config file

Test that this worked via a terminal: ssh argos_container~localhost and you should be dropped into a running instance of the container. Note: if you have to type your password, you can setup ssh keys.

Next, Open VS Code and press Ctrl+Shift+P to bring up the interactive menu and type Open Settings (JSON). Select the result that matches (hint: likely 1st). Make the settings.json file include something like the following.

VS Code settings.json file

Then go to the extensions tab (Ctrl+Shift+X) and install the extension Remote — SSH. Once it is installed, click the button Switch to Pre-Release Version to get the latest version (this is needed as of version 0.71).

Finally, click the ssh button in the bottom left >< (or press Ctrl+Shift+P then typeConnect to Host). Select argos_container~localhost and you should now be connected to an Apptainer instance. Just like normal, open up a workspace folder, I selected the ~/test_proj. Note that the C/C++ extension needs installed into the ssh environment which can be done by just going to the extensions tab, finding it in the list, and clicking Install in SSH: ....

Intellisense inside the Apptainer container demonstration.

Congrats! you should now have VS Code Intellisense working while the libraries are not installed directly on your system. Try it out by right clicking on a function call→Peek→Peek Definition. Give the tutorial a clap if it helped you out, and comment below for anything.

If you run into any errors with connecting from within VS Code, you may simply need to kill off some old processes: sudo pkill vscode

As promised, the .cpp and .h files I used in the project are below:

.cpp and .h files from the project space

--

--

Davis Catherman

Intern @ Waymo (an Alphabet Company) and PhD student researching swarm & multi-agent systems @ Worcester Polytechnic Institute (WPI)