Sometimes called a definition file.
Tells Singularity how to build the container.
Bootstrap: debootstrap
OSVersion: bionic
MirrorURL: http://us.archive.ubuntu.com/ubuntu/
%help
A container with a bunch of fun programs installed.
%environment
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export PATH=/usr/games:"$PATH"
%post
apt update
apt install -y software-properties-common
apt-add-repository universe
apt update
DEBIAN_FRONTEND=noninteractive apt install -y cmatrix cowsay fortune
echo "export PATH=/usr/games:$PATH" >> "$SINGULARITY_ENVIRONMENT"
%test
export PATH=/usr/games:"$PATH"
command -v cowsay >/dev/null 2>&1 || { echo >&2 "I require cowsay but it's not installed. Aborting."; exit 1; }
command -v fortune >/dev/null 2>&1 || { echo >&2 "I require fortune but it's not installed. Aborting."; exit 1; }
command -v cmatrix >/dev/null 2>&1 || { echo >&2 "I require cmatrix but it's not installed. Aborting."; exit 1; }
%runscript
if [ $# -eq 0 ]
then
fortune | cowsay
else
cowsay "$@"
fi
%labels
Author Michael Hall
Version v0.0.1
Bootstrap: debootstrap
OSVersion: bionic
MirrorURL: http://us.archive.ubuntu.com/ubuntu/
Tells Singularity the base operating system you would like your container to be built with.
Other options include:
Bootstrap: docker
From: tensorflow/tensorflow
Bootstrap: shub
From: mbhall88/Singularity_recipes:template
Executed during the build process. If any step in any section fails, so does the build.
Useful for describing to others what your container is intended to do
%help
A container with a bunch of fun programs installed.
singularity run-help fun.sif
Define environment variables that will be available at runtime (i.e not available during build)
Can also add to environment with $SINGULARITY_ENVIRONMENT
%environment
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export PATH=/usr/games:"$PATH"
echo "export foo=bar" >> "$SINGULARITY_ENVIRONMENT"
This is what runs after the base OS is installed. Use this to install software, download data, create directories etc.
%post
apt update
apt install -y software-properties-common
apt-add-repository universe
apt update
DEBIAN_FRONTEND=noninteractive apt install -y cmatrix cowsay fortune
echo "export PATH=/usr/games:$PATH" >> "$SINGULARITY_ENVIRONMENT"
Runs at the end of the build process. I STRONGLY encourage you to put tests in your definition.
Use --notest
to skip tests 😒
%test
export PATH=/usr/games:"$PATH"
command -v cowsay >/dev/null 2>&1 || \
{ echo >&2 "I require cowsay but it's not installed. Aborting."; exit 1; }
command -v fortune >/dev/null 2>&1 || \
{ echo >&2 "I require fortune but it's not installed. Aborting."; exit 1; }
command -v cmatrix >/dev/null 2>&1 || \
{ echo >&2 "I require cmatrix but it's not installed. Aborting."; exit 1; }
singularity test fun.simg
# build without tests using --notest
sudo singularity build --notest fun.sif Singularity.fun
Is run when invoked with the singularity run
command or executed with ./my.sif
%runscript
if [ $# -eq 0 ]
then
fortune | cowsay
else
cowsay "$@"
fi
./fun.sif Holy cow!
___________
< Holy cow! >
-----------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
singularity run fun.sif
___________________________
< Condense soup, not books! >
---------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Used to add metadata to the container with a name-value pair format.
Inspect the metadata of a container
%labels
Author Michael Hall
Version v0.0.1
singularity inspect fun.sif
{
"Author": "Michael Hall",
"Version": "v0.0.1",
"org.label-schema.build-date": "Tuesday_19_February_2019_11:38:35_UTC",
"org.label-schema.build-size": "611MB",
"org.label-schema.schema-version": "1.0",
"org.label-schema.usage": "/.singularity.d/runscript.help",
"org.label-schema.usage.singularity.deffile": "Singularity.template",
"org.label-schema.usage.singularity.deffile.bootstrap": "shub",
"org.label-schema.usage.singularity.deffile.from": "mbhall88/Singularity_recipes:template",
"org.label-schema.usage.singularity.deffile.mirrorurl": "http://us.archive.ubuntu.com/ubuntu/",
"org.label-schema.usage.singularity.deffile.osversion": "bionic",
"org.label-schema.usage.singularity.runscript.help": "/.singularity.d/runscript.help",
"org.label-schema.usage.singularity.version": "3.0.3-1.el7"
}
sudo singularity build <image name> <target>
Need root (
sudo singularity build <image name> <target>
<target>
can be:
sudo singularity build <image name> <target>
<image name>
should have the .sif
(
Singularity Image File) extension.
sudo singularity build fun.sif Singularity.fun
Versions prior to 3.0 use .simg
Create a clean container and open a blank text file
Bootstrap: debootstrap
OSVersion: bionic
MirrorURL: http://us.archive.ubuntu.com/ubuntu/
%post
apt update
apt install -y software-properties-common
apt-add-repository universe
apt update
Singularity.template
Create a clean container and open a blank text file
sudo singularity build --sandbox container-dev Singularity.template
Shell into the sandbox
sudo singularity shell --writable container-dev
# should see the prompt change to something like
Singularity container-dev:~>
If you don't use --writable you won't be able to install anything or do anything that basically changes the size of the container
Shell into the sandbox
Warning: The directory /root
from you local machine will be mounted in the sandbox. So anything you do in the sandbox in that directory will also be reflected in the /root
directory locally.
Fix: Move out of /root
within the sandbox and do all of your work there. I personally tend to use /usr/local
or you could create a new directory altogether (but outside /root
) e.g /sandbox
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda3.sh
apt install -y wget
bash miniconda3.sh -b -p "$HOME"/miniconda
conda list
export PATH="$HOME/miniconda/bin:$PATH"
source $HOME/miniconda/bin/activate
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda3.sh
conda install -y -c bioconda bwa
Turn it into a recipe, build, test.
Choose a software program and make a singularity container for it.