4.6 Instances

Also know as services. Despite Docker it is still more convenient for these tasks, it allows enabling thing such as webservices (e.g., via APIs) in HPC workflows. Instead of defining a %runscript block, we define a %startscript one. So, it would be possible to have both if needed.

Simple example:

Bootstrap: docker
From: library/mariadb:10.3

%startscript
        mysqld
    sudo singularity build mariadb.sif mariadb.singularity

    mkdir -p testdir
    mkdir -p testdir/db
    mkdir -p testdir/socket

    singularity exec -B ./testdir/db:/var/lib/mysql mariadb.sif mysql_install_db

    singularity instance start -B ./testdir/db:/var/lib/mysql -B ./testdir/socket:/run/mysqld mariadb.sif mydb

    singularity instance list

    singularity exec instance://mydb mysql -uroot

    singularity instance stop mydb
When exposing ports below 1024 in a LINUX machine, administrator (sudo) privileges are needed. Historical reference: https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html
Specially with instances (but not only), if you encounter some permission problems you may need to enable write permissions in the image. If you do not want changes to persist in the image, you may want to use the –writable-tmpfs option. Changes are stored in an in-memory temporary filesystem which is discarded as soon as the service stops. More details about special storage options with Singularity: https://sylabs.io/guides/3.7/user-guide/persistent_overlays.html

More information: