Skip to content

Instantly share code, notes, and snippets.

@unode
Last active October 28, 2025 18:25
Show Gist options
  • Select an option

  • Save unode/c7d3761dce39b8023d0f241656dd8e2d to your computer and use it in GitHub Desktop.

Select an option

Save unode/c7d3761dce39b8023d0f241656dd8e2d to your computer and use it in GitHub Desktop.
Apptainer / Singularity as drop-in binary replacement
Using apptainer/singularity containers as drop-in binary replacements.
The `runscript` section in `Apptainer` is where all the magic happens:
Build normally with:
```
$ apptainer build container.sif Apptainer
```
And then magic:
```
$ ln -s container.sif base
$ ln -s container.sif hellobob
$ ./base
Hello!
$ ./hellobob
Hello!
Hello BOB
```
`container.sif` is executable by default so we can execute directly.
One can also simply do:
```
$ export PATH=".:$PATH"
$ hellobob
Hello!
Hello BOB
```
Turning them into fat binaries but still a perfect drop-in so long `apptainer` or `singularity` is installed on the system.
`head container.sif` tells the full story but the entry point is:
```
$ PATH="." hellobob
/usr/bin/env: ‘run-singularity’: No such file or directory
```
BootStrap: docker
From: debian:stable
%post
echo '#!/usr/bin/env sh' > /usr/local/bin/base
echo 'echo "Hello!"' >> /usr/local/bin/base
chmod +x /usr/local/bin/base
cp /usr/local/bin/base /usr/local/bin/hellobob
echo 'echo "Hello BOB"' >> /usr/local/bin/hellobob
chmod +x /usr/local/bin/hellobob
%runscript
/usr/local/bin/$APPTAINER_NAME "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment