SingularityContainerCreation: Difference between revisions

From T2B Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:


<pre>
<pre>
sudo singularity build --sandbox test1.img test1.def
$ sudo singularity build --sandbox test1.img test1.def
</pre>
</pre>
after one or two minutes, you get an container ready to be used under the form of a directory test1.img.
after one or two minutes, you get an container ready to be used under the form of a directory test1.img.
Now, let's say you want to install vim inside the container. Issue the following command :
<pre>
$ sudo singularity shell --writable test1.img
Singularity: Invoking an interactive shell within container...
Singularity test1.img:~>
</pre>
The "--writable" flag is really important if you want to bring modifications inside the image.


= Sources =
= Sources =
* [https://www.sylabs.io/docs/ Singularity website] -> explanations to build a container on this [https://www.sylabs.io/guides/2.6/user-guide/build_a_container.html page].
* [https://www.sylabs.io/docs/ Singularity website] -> explanations to build a container on this [https://www.sylabs.io/guides/2.6/user-guide/build_a_container.html page].

Revision as of 15:46, 30 October 2018

Prerequisites

By default, ordinary users don't have the right to create Singularity containers. You must either do it as root, or to work with sudoer account (the best option !).

Creation of a containers

On this page, we will not explain all the methods that exist to build a container, this is already done here. Instead, we will illustrate one method that can rapidly be adopted.

Creation of a container using a definition file

A definition file is a recipe to build a container starting from something else, generally another Singularity or Docker container. Let's create a definition file 'test1.def' with the following content :

Bootstrap: docker

From: centos:latest

The first line indicates that we will use a container from Docker hub, the second line specifies which container (the latest release of CentOS).

Now, if you issue the following command :

$ sudo singularity build --sandbox test1.img test1.def

after one or two minutes, you get an container ready to be used under the form of a directory test1.img.

Now, let's say you want to install vim inside the container. Issue the following command :

$ sudo singularity shell --writable test1.img
Singularity: Invoking an interactive shell within container...

Singularity test1.img:~> 

The "--writable" flag is really important if you want to bring modifications inside the image.

Sources