Building a Basic Container
The information can be taken from https://github.com/NIH-HPC/Singularity-Tutorial. I’m just documenting what I understand step-by-step
In Order for you to build a Container, you have to use a build command. The build command does the following
- Installs an OS
- Setup the Container’s Environment
- Install the apps required
Singularity Flow – Standard Development Cycle
- Create a writable container (called a sandbox)
- Shell into the container with the –writable option and tinker with it interactively
- Record changes that we like in our definition file
- Rebuild the container from the definition file if we break it
- Rinse and Repeat
- Rebuild the container from the final definition file as a read-only singularity image format (SIF) image for use in production
Let’s Build – Using the examples.
You can git clone Singularity Download Page and the examples is provided there.
% git clone https://github.com/sylabs/singularity.git
% mkdir ~lolcow
% cd singularity/examples/debian/Singularity ~/lolcow/lolcow.def
% cd ~/lolcow
% vim lolcow.def
BootStrap: debootstrap
OSVersion: stable
MirrorURL: http://ftp.us.debian.org/debian/
%runscript
echo "This is what happens when you run the container..."
%post
echo "Hello from inside the container"
apt-get -y --allow-unauthenticated install vim
You can find more information on the Singularity Definition Files
Developing a new container
To build a container, you will need sudo privilege or root access
% sudo singularity build --sandbox lolcow lolcow.def
- Container: lolcow
- Definition File: lolcow.def
- Build a Container for Development Purposes: –sandbox
After firing the command, you will have a basic Debian contained saved in a local directory called lolcow
Explore and modify the container
In order to obtain root privileges within the root container, you will need root at the Host System
% sudo singularity shell --writable lolcow
The –writable option allows us to modify the container. The corresponding changes will be saved into the container and persist across uses.
Installing Packages in Singularity
Once inside the shell, you can modify the container and it will be saved persistently.
Singularity > apt-get install -y fortune cowsay lolcat
you have to PATH it so that container can find the binary
Singularity > export PATH=$PATH:/usr/games
Singularity> fortune | cowsay | lolcat
________________________________________
/ Q: Why haven't you graduated yet? A: \
| Well, Dad, I could have finished years |
| ago, but I wanted |
| |
\ my dissertation to rhyme. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Building Production Grade
If you ultimately want all of these changes to be reflected in your definition file. Let’s update our definition file
% nano lolcow.def
BootStrap: debootstrap
OSVersion: stable
MirrorURL: http://ftp.us.debian.org/debian/
%runscript
echo "This is what happens when you run the container..."
%post
echo "Hello from inside the container"
apt-get update
apt-get -y install fortune cowsay lolcat
%environment
export PATH=$PATH:/usr/games
To rebuild the image from the definition, make sure you have the necessary yum package in your host.
# yum install debootstrap
# yum install squashfs-tools
If you are having further issues, make sure your hosts has the prerequistics packages installed. It can be found at https://github.com/NIH-HPC/Singularity-Tutorial/tree/master/01-installation
Building the Container
# singularity build lolcow.sif lolcow.def
.....
.....
INFO: Adding environment to container
INFO: Adding runscript
INFO: Creating SIF file...
INFO: Build complete: lolcow.sif
References: