Warning
This is as a Lab Notebook which describes how to solve a specific problem at a specific time. Please keep this in mind as you read and use the content. Please pay close attention to the date, version information and other details.
Connecting to a Singularity container with VS Code (updated 2023-11-03)
Problem setup
A user has a Singularity image containing an installation of a Python installation they use to run their Python code which includes specific scientific libraries. This user also writes code in Visual Studio Code on Windows, and uses things like the integrated debugger, the integrated terminal, and the Python extension for autocomplete.
The user would like to connect VS Code to their Singularity container so that VS Code can integrate the environment and Python installation within the container into its IDE features.
Solution
This solution is based on the following Github comment and issue.
Set up the SSH configuration
If you haven't already, follow the instructions to connect to the HPCC through SSH.
Press F1 to open the command pallette and begin typing "Remote-SSH: Open SSH Configuration File...", press Enter. Select the file C:\Users\<Account_Name>\.ssh\config
.
Add a new section to the SSH configuration file with the following lines, making sure to replace the pieces in brackets (<>
) with your information:
1 2 3 4 5 6 |
|
Above, change <container>
to a shortname for your container, <netid>
to your NetID that you use to access the HPCC, and <path_to_singularity_image>.sif
to be the location of your Singularity image on the HPCC. For example, I (grosscra
) tested this using a Singularity image on the HPCC at ~/tensorflow_latest-gpu-jupyter.sif
with Tensorflow installed. So the configuration looks like
1 2 3 4 5 6 |
|
You are also free to change the development node to whatever node you like in the Host
and HostName
lines.
Set up VS Code settings
We will now set up VS Code so that when it connects to the <container>~intel18
host through the "Remote - SSH" extension, it will run the RemoteCommand
set above to start the container.
Open the VS Code Settings JSON files by pressing F1, and type Preferences: Open User Settings (JSON).
Important: Make sure you edit the JSON files directly, do not manipulate the settings using VS Code's menu. There is a bug that does not allow you to set the correct settings from the menu.
Add the following lines, or if they are already there, ensure that they have these values, replacing <container>
with the short name you used in the SSH configuration above and <Windows_Account_Name>
with your Windows account:
1 2 3 4 5 6 7 8 9 10 |
|
Note that the SSH configuration file path above uses forward-slashes instead of back-slashes.
Additionally, if you have a remote.SSH.remotePlatform
section in your settings.json
with a line corresponding to your <container>~intel18
section, remove it. For example, if my settings.json
has the lines
1 2 3 4 5 6 7 8 |
|
I should remove the "tf~intel18": "linux"
line.
Kill VS Code Servers
To ensure that your new connection does not reuse any old connections, you will need to kill those old connections if they exist.
Press F1 and type the command "Remote-SSH: Kill VS Code Server on Host...". If the option appears, choose intel18
(or whatever development node you're using). Repeat and choose the <container>~intel18
option.
Press F1 and type the command "Remote-SSH: Kill Local Connection Server For Host...". If the option appears, choose intel18
(or whatever development node you're using). Repeat and choose the <container>~intel18
option.
Start the connection
You are now ready to start the connection. In the future, this is the only step you need to do.
Press F1 and type the command "Remote-SSH: Connect to Host...". Choose the <container>~intel18
option and you should be connected to a VS Code instance running inside your container.