# Singularity Build Basics Documentation: https://docs.sylabs.io/guides/latest/user-guide/build_a_container.html ------------------------------------------------------------------------------- ### Build Input The **build** command accepts a target as input and produces a container as output. The type of target given determines the method that build will use to create the container. It can be one of the following: * URI beginning with library:// to build from the Container Library ``` singularity build lolcow.sif library://lolcow ``` * URI beginning with docker:// to build from Docker Hub ``` singularity build lolcow.sif docker://sylabsio/lolcow ``` * URI beginning with shub:// to build from Singularity Hub * path to an existing container on your local machine * path to a directory to build from a sandbox * path to a SingularityCE definition file -------------------------------------------------------------------------------- ### Build Output **Build** can produce containers in two different formats: * a compressed read-only Singularity Image File (SIF) format, suitable for production (default) * a writable (ch)root directory called a sandbox, for interactive development(--sandbox option) --------------------------------------------------------------------------------- ### Create Sandbox Singularities ``` sudo singularity build --sandbox lolcow/ library://lolcow ``` To make persistent changes within the sandbox container, use the --writable flag when you invoke your container. ``` sudo singularity shell --writable lolcow/ ``` ------------------------------------------------------------------------------- ### Converting Containers If you had a sandbox container called development/ and you wanted to convert it to SIF container called production.sif, you could do so as follows ``` sudo singularity build production.sif development/ ``` ------------------------------------------------------------------------------- ### Building Containers from File Create definition files called lolcow.def: ``` Bootstrap: docker From: ubuntu:22.04 %post apt-get -y update apt-get -y install cowsay lolcat %environment export LC_ALL=C export PATH=/usr/games:$PATH %runscript date | cowsay | lolcat ``` Build singularity with: ``` sudo singularity build lolcow.sif lolcow.def ``` In this case, we’re running singularity build with sudo because installing software with apt-get, as in the %post section, requires the root privileges. By default, when you run SingularityCE, you are the same user inside the container as on the host machine. Using sudo on the host, to acquire root privileges, ensures we can use apt-get as root inside the container. If you aren’t able or do not wish to use sudo when building a container, SingularityCE offers several other options: **--remote builds**, a **--fakeroot mode**, and limited unprivileged builds using **proot**.