Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote container with Singularity #3066

Open
statiksof opened this issue May 28, 2020 · 99 comments
Open

Remote container with Singularity #3066

statiksof opened this issue May 28, 2020 · 99 comments
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality

Comments

@statiksof
Copy link

Is it possible to use singularity containers instead of Docker? We only provide Singularity on our remote machines.

@Chuxel
Copy link
Member

Chuxel commented May 28, 2020

Not today. Only Docker is fully supported today. Kubernetes has attach support and Podman works with some limitations.

@Chuxel Chuxel added feature-request Request for new features or functionality containers Issue in vscode-remote containers labels May 28, 2020
@statiksof
Copy link
Author

@Chuxel thanks for the quick answer. Actually, I though that I can overcome the glibc issue by using containers. Is there any other workaround to make the remote ssh works? I have glibc 2.12.

@Chuxel
Copy link
Member

Chuxel commented May 28, 2020

Not today - Node, V8, and even Chrome require recent versions of glibc unfortunately.

@statiksof
Copy link
Author

Just an update, I can start the vscode-server inside the singularity container. It starts without any issue. The problem now is how to forward ssh or config the ssh extension locally to use this server.

@oschulz
Copy link

oschulz commented Sep 25, 2020

I would love to see support for Singularity containers, together with other container systems like Shifter and Charliecloud that are popular in scientific (resp. HPC/HTC) computing environments.

I currently use a very clunky workaround:

  • I use a custom SSH script (via VSCode config option"remote.SSH.path") that sets an env var LC__SINGULARITY_IMAGE (different images can be chosen depending on the name of the target system) and then does exec ssh "$@". Env vars starting with LC_* (and only those) are usually forwarded by SSH.

  • I modify "$HOME/.vscode-server/bin/*/server.sh", and add change "$ROOT/node ..." to singularity run "$LC__SINGULARITY_IMAGE" $ROOT/node ..."

It works, but it's not very convenient. "server.sh" needs to be modified after every update of vscode-server, and since the server instance gets reused, only one container instance can be active on a given remote system at the same time.

@oschulz
Copy link

oschulz commented Sep 25, 2020

A first step to make it easier for users to use custom container runtimes might be to add a configuration option like "remote.SSH.runwith". It would allow the user to specify a wrapper script for the vscode server. That user-specified wrapper script would be required to end with exec $@, so that "remote.SSH.runwith" = "run_in_my_container.sh" would result in run_in_my_container.sh "$ROOT/node" ${INSPECT:-} "$ROOT/out/vs/server/main.js" "$@" or run_in_my_container.sh /path/to/server.sh ....

If VS Code would also set some env vars before calling that wrapper script, forwarding information like workspace path, then the wrapper script could decide which container image to run, and how, depending on the application.

@statiksof
Copy link
Author

@oschulz thank you for sharing your workaround. I finally got it to work after multiple refinements. For me, forwarding the LC* didn't work. So, I spent most of the time modifying server.sh. I used a default centos 7 image just for testing, there are some warnings when the agent starts, I am thinking to provide dedicated images for that purpose.

@oschulz
Copy link

oschulz commented Oct 1, 2020

For me, forwarding the LC* didn't work.

Unfortunately, that depends on the SSH server config - I guess some sites disable it, and users don't have control over the server config, of course.

@RobertRosca
Copy link

The instructions for using Podman with the remote containers are here: https://code.visualstudio.com/docs/remote/containers#_can-i-use-podman-instead-of-docker

It just suggests pointing the docker executable path to the podman path, and it works as podman and docker have similar CLI commands.

One solution would be to create a wrapper for Singularity which parses and 'translates' the docker commands into Singularity commands. This is similar to the workaround mentioned here int this comment above #3066 (comment) but it's slightly less clunky.

I'll add this to my list of cool things to maybe work on, but probably won't get to it. If anybody here is interested I'm willing to help out though.

@oschulz
Copy link

oschulz commented Feb 18, 2021

Thanks @RobertRosca , I'll definitely try that, such a wrapper should be possible. Will post if it works.

@david-macleod
Copy link

david-macleod commented Feb 20, 2021

Another workaround (#4474) using a modified version of the remote extension (which will hopefully make it into the default extension soon) allows specifying the singularity exec in .ssh/config e.g.

Host blah
    User blah
    HostName blah
    RemoteCommand "/usr/local/bin/singularity exec $CONTAINER_IMAGE /bin/bash"

@oschulz
Copy link

oschulz commented Feb 20, 2021

I guess the ideal solution would be a config option for remote-ssh that allows the user to specify an arbitrary command that gets inserted before "$ROOT/node [...]. That way, one could use workspace-dependent containers, etc.

Was trying to prototype something like that, but to my knowledge the source code of the remote-ssh extension isn't available in unmangled form. Should be trivial to do for the VS code team, though.

@oschulz
Copy link

oschulz commented Feb 20, 2021

Thanks @RobertRosca , I'll definitely try that, such a wrapper should be possible. Will post if it works.

I played a bit with this, but it's tricky because Singularity (and similar scientific container runtimes like Shifter and Charliecloud) are very different from docker - they don't have a background service, they just run the container directly, there's only one process. So things like docker ps -q don't really exist. It's much closer to a glorified chroot, instead.

@RobertRosca
Copy link

@oschulz Hmm good point, there aren't analogs for all of the commands you can do in docker in singularity, but most things are possible, singularity actually has decent OCI Runtime Support built in already.

In Singularity you can run containers as a background service, this is called a container instance instance, you can also run containers as OCI compliant instances which gives you JSON-format outputs for the state of the container which have the pattern OCI expects.

So if you start a container with singularity instance start ..., it runs as a background process, and you can then do singularity instance list to get a list of running instances which is pretty similar to docker ps -q.

Played around a bit with the vscode remote docker extension and the calls it makes are usually like:

[254405 ms] Start: Run: docker context show
[254423 ms] Start: Run: docker context show
[254442 ms] Start: Run: docker context inspect --format {{.Name}}
[254464 ms] Start: Run: docker context inspect --format {{.Name}}
[254496 ms] Start: Run: docker version --format {{.Server.APIVersion}}
[254531 ms] 1.41
[254532 ms] Start: Run: docker -v
[254561 ms] Start: Run: docker events --format {{json .}} --filter event=create --filter event=destroy --filter event=die --filter event=health-status --filter event=kill --filter event=pause --filter event=rename --filter event=resize --filter event=restart --filter event=start --filter event=stop --filter event=unpause --filter event=update --filter event=exec_create
[254568 ms] Start: Run: docker ps -q -a
[254616 ms] Start: Run: docker inspect --type container  # Ran on all containers

That's just done as the setup, now when you select a container to attach to it runs:

[299720 ms] Start: Run: docker inspect --type container aba69f4...
[299760 ms] Start: Run: docker start #  Ran on the container you selected to attach to
[301149 ms] Start: Run: docker inspect --type container aba69f4...

On the 'local' client, and then the following runs on the 'remote' client:

[3 ms] Remote-Containers 0.161.0 in VS Code 1.54.0-insider (a699ffaee62010c4634d301da2bbdb7646b8d1da).
[9 ms] Start: Run: docker context show
[53 ms] Start: Run: docker context inspect --format {{.Name}}
[84 ms] Start: Run: docker context show
[87 ms] Start: Resolving Remote
[88 ms] Setting up container: /vscode_test_container
[89 ms] Start: Run: docker inspect --type container /vscode_test_container
[119 ms] Start: Run: docker context inspect --format {{.Name}}
[133 ms] Start: Check Docker is running
[133 ms] Start: Run: docker version --format {{.Server.APIVersion}}
[170 ms] Server API version: 1.41
[171 ms] Start: Inspecting container
[171 ms] Start: Run: docker inspect --type container aba69f4...
[198 ms] Start: Run: docker exec -i -u root -e VSCODE_REMOTE_CONTAINERS_SESSION=8033a654-1097-4d65-9b42-b6472cfb27df1613987151778 aba69f4... /bin/sh
[201 ms] Start: Run in container: uname -m
[231 ms] Start: Run in container: cat /etc/passwd

You can place various additional flags to be passed to this in a runArgs variable, either with docker-compose or devcontainer files, which would let you set some additional flags for Singularity (e.g. containall).

I've made a (empty) repo here: https://github.com/RobertRosca/singularity-vscode-devcontainer

And an initial dev issue collecting some info: RobertRosca/singularity-vscode-devcontainer#2

@oschulz
Copy link

oschulz commented Feb 22, 2021

In Singularity you can run containers as a background service

Hm, good point, have to look into that (and check if it requires permissions that plain users on scientific compute clusters might not get, they tend to be restrictive).

@RobertRosca
Copy link

RobertRosca commented Feb 22, 2021

Hm, good point, have to look into that (and check if it requires permissions that plain users on scientific compute clusters might not get, they tend to be restrictive).

Should be fine, I've only glanced through the code but as far as I understand it instances work in a pretty simple way. When you start an instance it starts a container as a background process and then (by default) writes the PID and some other info to the users home directory (e.g. ~/.singularity/instances/sing/$HOSTNAME/$USERNAME) in JSON files.

After that all the commands that interact with instances (e.g. list, stop, log, run, attach, etc...) look through that directory to find the PID/other relevant info, and use that PID to communicate with the background container. As long as the user can start singularity containers and the instance JSON files can be written then it should work fine. I currently use singularity instances on the cluster at work and haven't had any issues with them.

@oschulz
Copy link

oschulz commented Feb 22, 2021

Great, thanks for the details!

@PavelSosin-320
Copy link

PavelSosin-320 commented Feb 23, 2021 via email

@oschulz
Copy link

oschulz commented Feb 23, 2021

Should be fine, I've only glanced through the code but as far as I understand it instances work in a pretty simple way.

This might indeed work nicely with singularity. The problem is that other relevant container runtimes like Shifter and Charliecloud do (AFAIK) not support instances.

In the end, a simple option in VS-code that allows for an arbitrary prefix commands before the vscode-server starts (so like it was put before "$ROOT/node [...] in the server start script) would probably be the most flexible solution.

@mathiaswagner
Copy link

mathiaswagner commented May 14, 2021

I used a separate ssh-key and in the remote host's authorized_keys I prefix that special public key key with

command="singularity run image.sif $SSH_ORIGINAL_COMMAND"

This seems to work.

On my local host I have in my .ssh/config

Host vscoderemote
HostName remote
IdentityFile /path/to/ssh-key-for-code

@oschulz
Copy link

oschulz commented May 14, 2021

Neat!

@DraTeots
Copy link

DraTeots commented May 23, 2021

@PavelSosin-320 I don't understand what is the goal of the herd race toward already obsolete Client-Server architecture in the development environment

Well... You don't understand =) Since singularity is in play, it is highly probably a scientific environment, where software part is usually understaffed and software consists of crappy monster packages like CERN ROOT. Some software from the stack is new and demanding (c++17, newest compilers, look at ACTS tracking), some other software is 50 years old, all developers are passed away and nobody touches it as it works but requires old versions of Fortran. End everything is wired together with lots of environment variables, hacks and patches. Building such stack from scratch make take days of fails and gotchas. Images are 7-8GB stuffed of scientific dependencies where "everything works, don't touch". Understaffed maintainers cannot provide sane stably working installation solutions other than containers. Please, try to build something like sPHENIX software stack and then come back to this issue as new person who now understands all.

Docker container support in VSCode is superb and it is pleasure to develop in the container. But in many scientific communities docker is given up in favor of Singularity. Such plugin would greatly improve situation for many scientists.

@oschulz
Copy link

oschulz commented May 23, 2021

I don't understand what is the goal of the herd race toward already obsolete Client-Server architecture in the development environment [...]It requires extra hardware

It's not so much about plain software development for generic applications (write on your local system, test on your local system, deploy to the cloud or so).

As it turns out, VS code is an great tool for scientific coding and analysis. So code is written, but it's constantly changed, plots are made, data is analysed, code is adapted, and to on. That often requires systems or compute clusters with capabilities far beyond a laptop or desktop machine, and indeed sometimes special hardware like state of the art GPUs, etc.

@oschulz
Copy link

oschulz commented May 23, 2021

Ah, I forgot - also, in typical scientific computing environments (central home directories, no root privileges for users on desktops or severs) Docker can't really be used safely, so Singularity & friends (locally and remote) have become very common.

@PavelSosin-320
Copy link

Singularity, Docker, Podman, Buildah, Kubernetes & friends share the same Image standard - OCI. The Image built using one of the listed tools can be run in any other tool almost without effort. The OCI runtime can run on any scale, from Podman Linux CLI to Kubernetes clusters. The client-Server architecture is the personal developer choice, there is no herd race here today. Every developer can make the choice to use everything on a single laptop or use a Cloud-based development pipeline. Base docker images for NVidia GPU are available from NVidia, they can be used on almost any hardware with NVidia GPU, from the laptop to Cloud infrastructure like AWS, GCP. So Creation of the Docker image is a one-time investment that makes software portable forever. My choice today is Podman at home and RedHat dev pipeline for big projects with complex integration.
Tlalks about Docker safety is bullshit today, Banks and Government defense bodies use Kubernetes because it offers better security frameworks.

@PavelSosin-320
Copy link

PavelSosin-320 commented May 23, 2021 via email

@DebajyotiS
Copy link

@patgo25, did you also have a proxy jump? The issue is it works normally on a terminal. So it really just looks like VSCode doesn't recognise my remoteCommand

@DebajyotiS
Copy link

@oschulz Interestingly, if I explicitly set useLocalServer to true, I can't seem to use ssh at all through vscode (note, that I had this checked in the settings).

It is only after setting it to false that I can ssh in.

    "editor.inlineSuggest.enabled": true,
    "remote.SSH.connectTimeout": 30,
    "remote.SSH.useLocalServer": false,
    "remote.SSH.enableRemoteCommand": true,
    "remote.SSH.logLevel": "trace",

@oschulz
Copy link

oschulz commented Apr 8, 2022

if I explicitly set useLocalServer to true, I can't seem to use ssh at

I have to admit I don't know what's going on there ...

@DebajyotiS
Copy link

quick question on your custom run script that you use to export XDG runtime: is that path dependent?
Can I keep it in my home/dir
and then just have remoteCommand be /home/dir/script
or am I misunderstanding something?

@gipert
Copy link

gipert commented Apr 8, 2022

Sorry I cannot help a lot since I don't know Windows either... But, one additional piece of information: I had set up the thing on a student's Windows laptop a couple of months ago and it stopped working yesterday, after an Remote.SSH extension update (suspicious...). Might be related to your issue, I did not investigate further though.

@ravusairam
Copy link

@DebajyotiS I am also facing the same issue. I am able to ssh using windows powershell and it goes to the container on my remote machine. But, it doesn't work on vscode..Have you resolved the issue?

@DebajyotiS
Copy link

@ravusairam , Unfortunately not. See issues 6598 and 6086

@adinriv
Copy link

adinriv commented May 3, 2022

@DebajyotiS have you tried to set up a RemoteCommand that does a resource allocation (for instance srun or salloc) first and then spins the singularity container within that node?

I'm trying something on these lines and I'm seeing port forwarding errors. Yet the solution with singularity as in your example works.

@DebajyotiS
Copy link

@adinriv I haven't. I usually request a node from the terminal first, and then modify the config file accordingly which is a lot of steps for it to not work ultimately. Are you using windows or linux?

@adinriv
Copy link

adinriv commented May 3, 2022

I'm on linux. I wanted to spin VSCode within the container to ease the job of running jupyter notebooks within the containers.

If not, VSCode doesn't see the kernels inside it and do not work as well (at least I haven't made it work).

@MiguelRodo
Copy link

MiguelRodo commented Oct 5, 2022

To note, I've been able to run VSC inside a singularity container on a compute node on an HPC using the Visual Studio Code Server. All I did was add the install command (available at the link) to the image definition file and run singularity run <image> code-server in a compute node terminal.

@oschulz
Copy link

oschulz commented Oct 5, 2022

Oh, that's indeed an interesting new option!

@casjogreen
Copy link

Miguelrodo did you was able to install ms python extension?

@casjogreen
Copy link

miguelrodo, the complete question:
Did you install the ms python extension in your vscode-server inside your singularity image? I was able to install vscode desktop and run inside the singularity image. Still, I couldn't install the ms-python extension to debug with it inside the singularity image.

@casjogreen
Copy link

To note, I've been able to run VSC inside a singularity container on a compute node on an HPC using the Visual Studio Code Server. All I did was add the install command (available at the link) to the image definition file and run singularity run <image> code-server in a compute node terminal.

Did you install the ms python extension in your vscode-server inside your singularity image? I was able to install vscode desktop and run inside the singularity image. Still, I couldn't install the ms-python extension to debug with it inside the singularity image.

@MiguelRodo
Copy link

MiguelRodo commented Oct 10, 2022

Hi @casjogreen. Nope, sorry, I did not - the images I've used were for R data analyses. For what it's worth, I didn't install any VSC extensions inside the image itself or during the image build. I think VSC extensions are installed to ~/.vscode-server-insiders, so the VSC server should be able to install to there after the image is created and then run them. But I don't really know the nitty gritty of extensions, so that could be inaccurate or not the whole story.

@casjogreen
Copy link

Hi @casjogreen. Nope, sorry, I did not - the images I've used were for R data analyses. For what it's worth, I didn't install any VSC extensions inside the image itself or during the image build. I think VSC extensions are installed to ~/.vscode-server-insiders, so the VSC server should be able to install to there after the image is created and then run them. But I don't really know the nitty gritty of extensions, so that could be inaccurate or not the whole story.

Thank you

@ChristianEschen
Copy link

ChristianEschen commented Nov 3, 2022

Hi,
I am trying to install the IDE vscode inside a singularity container. To do so I have specified a Dockerfile as:

FROM nvcr.io/nvidia/pytorch:21.12-py3
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install software-properties-common apt-transport-https wget -y &&
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
RUN apt update -y
RUN apt install code -y

From the dockerfile I build the vscode_remote_development.sif
The next step is to run the singularity container: $singularity shell --nv -B vscode_remote_development.sif
I can start vscode in the singularity container with: $code .
Now, I need to manually install the python extension (I install it manually using "Install from VSIX.." using the GUI).
The installation succeeds but inside the run and debug tab the panel is empty (see attached image).
Screenshot from 2022-11-03 17-29-29

@casjogreen
Copy link

ChristianEschen The same happened to me, even though I tried to install the Python extension for vscode while creating the singularity image.

@R4dicalEdward
Copy link

R4dicalEdward commented Dec 14, 2022

Hi,
my workaround currently is to build a container with full linux distribution (ubuntu18.04) and install VS Code as well.

Bootstrap: docker
From: nvidia/cuda:11.3.1-devel-ubuntu18.04

I downloaded the . deb file first and made it available via

%files 
 code_1.73.1-1667967334_amd64.deb

but I think the wget-approach should lead to the same outcome.

In my %post-section I install everything I need (e.q. nano, git etc.) and then I install VS Code via:

apt-get install ./code_1.73.1-1667967334_amd64.deb -y

and then build my python env.

I'm able to open VS Code via:

singularity run /path/to/image/image.sif code

and install all extensions in the usual way via GUI. They will be installed into home/username/.vscode on your node.

This works just fine in my case.

NOTE: To open VS Code on compute node you need to connect to that node with X11 forwarding enabled (ssh -X).

Hope that helped.

@data-panda
Copy link

data-panda commented Jan 6, 2023

Has anyone tried to install the python extension to enable a debug session within the container? I tried the steps listed using the RemoteCommand method which worked fine but only suffices to edit and run the code. I installed the python extension but the activation of it fails with the following error:

image

Any help will be appreciated!

Edit1:
This is what I can see while I try to use developer tools and look at the console to figure out what is causing the problem. To me it seems like there is "socket" related error but I am far from typing/understanding a single line of typescript code to say it conculsively. Image attached below:

Edit2:
This turned out more to be a bug related to the VScode Insiders version that I was using. I figured it out when I was greeted with the same error while debugging a python code on my local machine. I tried running the same steps with VSCode stable and the python extension installed fine and got successfully activated to debug in all scenarios: local, remote, remote singularity container.

image

@dcat52
Copy link

dcat52 commented Jan 17, 2023

Hello @Chuxel
There seems to have been substantial development and ways people have gotten things to at least partially work. Also since the creation of this issue, Singularity has been accepted into the Linux Foundation community under the name Apptainer (https://www.linuxfoundation.org/press/press-release/new-linux-foundation-project-accelerates-collaboration-on-container-systems-between-enterprise-and-high-performance-computing-environments).

How can we work towards official support for Apptainer with this extension? If needing community-driven development, could you provide some information as to what developmentally needs to be completed to meet this goal?

@Chuxel
Copy link
Member

Chuxel commented Jan 23, 2023

The dev container spec is now open at https://containers.dev, and the reference implementation is at https://github.com/devcontainers/cli. The CLI is used under the hood by the Remote - Containers / Dev Containers extension and would also generally be by other dev container spec supporting tools. The vast majority of the VS Code server is in the https://github.com/microsoft/vscode repo as well. Those would be the best places to look to contribute. Also note that the Remote - Tunnels extension has come out recently to try to avoid SSH routing related issues.

@perrylets
Copy link

Has there been any progress on this?

@oschulz
Copy link

oschulz commented Jul 23, 2023

Has there been any progress on this?

The "RemoteCommand trick" works quite well, I'm using it regularly together with a little Apptainer-Wrapper called cenv - here a little HowTo: https://github.com/oschulz/container-env/blob/main/README-VSCode.md

It would be really nice not to have to set remote.SSH.serverInstallPath for every system/container-image. An environment variable to override remote.SSH.serverInstallPath would be really helpful.

@perrylets
Copy link

perrylets commented Jul 25, 2023

The "RemoteCommand trick" works quite well, I'm using it regularly together with a little Apptainer-Wrapper called cenv - here a little HowTo: https://github.com/oschulz/container-env/blob/main/README-VSCode.md

I have 25 hosts and 6 images, so it would take a while to do it. I will try it later when I have more time, though.

Besides that, I will only need to run one container per machine (at the same time), maybe there's a solution that's easier for a case like mine.

Edit to clarify:

I have more than one remote I can access, but I will only ever use 1 image per remote.
I can use any image on any remote, but I can never use 2 images at the same time in the same remote. I can have n images (they can be different images or the same image) running in n separate remotes at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests