1. How to build a singularity container in Ubuntu?

A singularity container is a very useful tool to pack all required softwares in a portable way so that they can be run accross different operating systems. As a typical use case, suppose that you would like to install a software in a high performance computing facility but you do not have an admin privilege. You can either bother the admin of the HPC everytime you want to install a software or you build a singularity container and you put all your required softwares in that container. Please refer to the web page of singularity to know more about its use and functionalities. In this article, I will give you a step by step guide on how to build a singularity container using ubuntu.

To build a singularity container, make sure that your operating system has singularity installed. First, check if singularity is already available or not by typing


on the terminal. If singularity is available, you should see instructions about its use and available commands. Otherwise you may see a command not found error.

1.1 Installing singularity in Ubuntu?

To install singularity, use the following commands on your terminal:

	sudo apt-get update && \
	sudo apt-get install -y build-essential \
	libseccomp-dev pkg-config squashfs-tools cryptsetup

	sudo rm -r /usr/local/go

	export VERSION=1.13.15 OS=linux ARCH=amd64 

	wget -O /tmp/go${VERSION}.${OS}-${ARCH}.tar.gz https://dl.google.com/go/go${VERSION}.${OS}-${ARCH}.tar.gz && \
	sudo tar -C /usr/local -xzf /tmp/go${VERSION}.${OS}-${ARCH}.tar.gz

	echo 'export GOPATH=${HOME}/go' >> ~/.bashrc && \
	echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
	source ~/.bashrc

	curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh |
	sh -s -- -b $(go env GOPATH)/bin v1.21.0

	mkdir -p ${GOPATH}/src/github.com/sylabs && \
	cd ${GOPATH}/src/github.com/sylabs && \
	git clone https://github.com/sylabs/singularity.git && \
	cd singularity

	git checkout v3.6.3

	cd ${GOPATH}/src/github.com/sylabs/singularity && \
	./mconfig && \
	cd ./builddir && \
	make && \
	sudo make install                   

1.2 Building a singularity container on Ubuntu?

Now, to build the singularity container, start by pulling the ubuntu operating system from docker

           sudo singularity pull docker://ubuntu:20.04

Use the following command if you want the latest version of ubuntu

           sudo singularity pull docker://ubuntu:latest

Now let's create a folder called ubuntu where we will install the software we need

           sudo singularity build --sandbox ubuntu/ ubuntu_20.04.sif

We will go inside the folder we have just created using the --writable command so that we have a write privilege

           sudo singularity exec --writable ubuntu/ /bin/bash 

The above command should bring you in a bash shell of the singularity container, we can now add a username and install some softwares

           adduser ianja
           apt-get install sudo
           usermod -aG sudo ianja

           apt-get update
           apt-get install wget
           apt-get install software-properties-common
           apt-get install vim
           apt-get install build-essential

Finally, let's build a singularity container called ubuntu.simg, which contains the softwares we have just installed

           sudo singularity build ubuntu.simg ubuntu/


Keep in touch