Skip to content

Commit 311cf00

Browse files
committed
Merge branch 'GodloveD-add-build-command' into docs/2.4
2 parents f545ca7 + 21c0df6 commit 311cf00

13 files changed

Lines changed: 223 additions & 172 deletions

_data/sidebars/user_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ entries:
2424
output: web, pdf
2525

2626
- title: Build a Container
27-
url: /docs-build
27+
url: /docs-build-container
2828
output: web, pdf
2929

3030
- title: Container Recipes

_posts/releases/2017-10-02-release-2.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Building an image is now more intuitive with the introduction of our `build` com
1717
sudo singularity build container.simg Singularity
1818
```
1919

20-
If you are tired of needing to estimate your image size, that issue goes away with build. The default format for a Singularity image base is now a smaller, compressed file format called **SquashFS**. This format is also a much better fit for reproducible containers, as it is immutable. For more details, see our [build](/docs-build) documentation.
20+
If you are tired of needing to estimate your image size, that issue goes away with build. The default format for a Singularity image base is now a smaller, compressed file format called **SquashFS**. This format is also a much better fit for reproducible containers, as it is immutable. For more details, see our [build](/docs-build-container) documentation.
2121

2222
**Build Bases**
2323
We originally supported just using an existing distribution package or docker as a base for building images. With 2.4, we have extended that set to include another Singularity image (`localimage`), a Singularity Hub or Registry image (`shub`) or the host operating system (`self`).

pages/docs/user-docs/action-bootstrap.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ folder: docs
66
toc: false
77
---
88

9-
>> Note: The bootstrap command is deprecated for Singularity Version 2.4. You should use <a href="/build" target="_blank">build</a> instead.
9+
> Note: The bootstrap command is deprecated for Singularity Version 2.4. You should use [build](/build-a-container) instead.
1010
11-
Bootstrapping was the original way (for Singularity versions prior to 2.4) to install an operating system and then configure it appropriately for a specified need. Bootstrap is very similar to build, except that it by default uses an <a href="https://en.wikipedia.org/wiki/Ext3" target="_blank">ext3</a> filesystem and allows for writability. The images unfortunately are not immutable in this way, and can degrade over time. As of 2.4, bootstrap is still supported for Singularity, however we encourage you to use <a href="/build" target="_blank">build</a> instead.
12-
13-
{% include toc.html %}
11+
Bootstrapping was the original way (for Singularity versions prior to 2.4) to install an operating system and then configure it appropriately for a specified need. Bootstrap is very similar to build, except that it by default uses an <a href="https://en.wikipedia.org/wiki/Ext3" target="_blank">ext3</a> filesystem and allows for writability. The images unfortunately are not immutable in this way, and can degrade over time. As of 2.4, bootstrap is still supported for Singularity, however we encourage you to use [build](/build-a-container) instead.
1412

1513

1614
## Quick Start

pages/docs/user-docs/action-build.md

Lines changed: 10 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -6,187 +6,45 @@ folder: docs
66
toc: false
77
---
88

9-
`build` is the "Swiss army knife" of container creation. You can use it to download and assemble existing containers from external resources like [Singularity Hub](https://singularity-hub.org/) and [Docker Hub](https://hub.docker.com/). You can use it to convert containers between the various formats supported by Singularity. And you can use it in conjunction with a [Singularity recipe](/docs-recipes) file to create a container from scratch and customized it to fit your needs.
9+
Use `build` to download and assemble existing containers, convert containers from one format to another, or build a container from a [Singularity recipe](/docs-recipes).
1010

1111
{% include toc.html %}
1212

1313
## Overview
14-
The `build` command accepts a target as input and produces a container as output.
14+
The `build` command accepts a target as input and produces a container as output. The target can be a Singularity Hub or Docker Hub URI, a path to an existing container, or a path to a Singularity Recipe file. The output container can be in squashfs, ext3, or directory format.
1515

16-
The target defines the method that `build` uses to create the container. It can be one of the following:
16+
For a complete list of `build` options type `singularity help build`. For more info on building containers see [Build a Container](docs-build-container).
1717

18-
- URI beginning with **shub://** to build from Singularity Hub
19-
- URI beginning with **docker://** to build from Docker Hub
20-
- path to a **existing container** on your local machine
21-
- path to a **directory** to build from a sandbox
22-
- path to an **archive** in .tar or compressed .tar.gz format
23-
- path to a **[Singularity recipe file](docs-recipes)**
24-
25-
In addition `build` can produce containers in three different formats. Formats types can be specified by passing the following options to build.
26-
27-
- compressed read-only **squashfs** file system suitable for production (default)
28-
- writable **ext3** file system suitable for interactive development (`--writable` option)
29-
- writable **(ch)root directory** called a sandbox for interactive development (`--sandbox` option)
30-
31-
Because `build` can accept an existing container as a target and create a container in any of these three formats you can convert existing containers from one format to another.
32-
33-
The following diagram illustrates the targets that can be supplied to `build` as inputs and the containers `build` can produce as outputs. Green arrows represent operations that can be carried out without root privileges (though the container may not perform properly when run as root). Red arrows represent operations that must be carried out with root privileges.
34-
35-
<div style="text-align: center">
36-
<a href="/assets/img/diagram/build_input_output.svg" target="_blank" class="no-after">
37-
<img style="max-width:500px" src="/assets/img/diagram/build_input_output.svg">
38-
</a>
39-
</div>
40-
41-
## Downloading a existing container from Singularity Hub
42-
You can use the `build` command to download a container from Singularity Hub.
18+
## Examples
19+
### Download an existing container from Singularity Hub or Docker Hub
4320

4421
```
4522
$ singularity build lolcow.simg shub://GodloveD/lolcow
46-
```
47-
48-
The first argument (`lolcow.simg`) specifies a path and name for your container. The second argument (`shub://GodloveD/lolcow`) gives the Singularity Hub URI from which to download.
49-
50-
But default the container will be converted to a compressed, read-only squashfs file. If you want your container in a different format use the `--writable` or `--sandbox` options.
51-
52-
## Downloading a existing container from Docker Hub
53-
You can use `build` to download layers from Docker Hub and assemble them into Singularity containers.
54-
55-
```
5623
$ singularity build lolcow.simg docker://godlovedc/lolcow
5724
```
5825

59-
The same information applies to containers built from Docker Hub and containers built from Singularity Hub.
60-
61-
## Creating `--writable` images and `--sandbox` directories
62-
63-
### `--writable`
64-
If you wanted to create a writable ext3 image similar to those used by Singularity version < 2.4, you could do so with the `--writable` option. You must create writable containers as root.
65-
66-
Extending the Singularity Hub example from above:
26+
### Create `--writable` images and `--sandbox` directories
6727

6828
```
6929
$ sudo singularity build --writable lolcow.img shub://GodloveD/lolcow
70-
71-
```
72-
73-
The resulting container is writable, but is still mounted as read-only when executed with commands such as `run`, `exec`, and `shell`. To mount the container as read-write when using these commands add the `--writable` option to them as well.
74-
75-
To ensure that you have the proper permissions to write to the container as you like, it is also a good idea to make changes as root. For example:
76-
77-
```
78-
$ sudo singularity shell --writable lolcow.img
79-
```
80-
81-
### `--sandbox`
82-
If you wanted to create a container within a writable directory (called a _sandbox_) you could do so with the `--sandbox` option. It's possible to create a sandbox without root privileges, but to ensure proper file permissions it is recommended to do so as root.
83-
84-
```
8530
$ sudo singularity build --sandbox lolcow/ shub://GodloveD/lolcow
8631
```
8732

88-
The resulting directory operates just like a container in an image file. You are permitted to make changes and write files within the directory, but those changes will not persist when you are finished using the container. To make your changes persistent, use the `--writable` flag when you invoke your container.
89-
90-
Once again, it's a good idea to do this as root to ensure you have permission to access the files and directories that you want to change.
91-
92-
```
93-
$ sudo singularity shell --writable lolcow/
94-
```
95-
96-
## Converting containers from one format to another
97-
If you already have a container saved locally, you can use it as a target to build a new container. This allows you convert containers from one format to another. For example if you had a squashfs container called `production.simg` and wanted to convert it to a writeable ext3 container called `development.img` you could:
98-
33+
### Convert containers from one format to another
34+
You can convert the three supported container formats using any combination.
9935
```
10036
$ sudo singularity build --writable development.img production.simg
101-
```
102-
103-
Similarly, to convert it to a writable directory (a sandbox):
104-
105-
```
10637
$ singularity build --sandbox development/ production.simg
107-
```
108-
109-
If you omit any options you can also convert your sandbox back to a read-only compressed squashfs image suitable for use in a production environment:
110-
111-
```
11238
$ singularity build production2 development/
11339
```
114-
You can convert the three supported container formats using any combination.
115-
116-
Use care when converting writable ext3 images or sandbox directories to the default squashfs file format. If changes were made to the writable container before conversion, there is no record of those changes in the Singularity recipe file rendering your container non-reproducible. It is a best practice to build your immutable production containers directly from a Singularity recipe file instead.
117-
118-
## Building containers from Singularity recipe files
119-
Of course, Singularity recipe files can be used as the target when building a container. For detailed information on writing Singularity recipe files, please see [the Container Recipes docs](docs-recipes).
120-
121-
Let's say you already have the following container recipe file called `Singularity`, and you want to use it to build a container.
122-
123-
```
124-
BootStrap: docker
125-
From: ubuntu:16.04
126-
127-
%post
128-
apt-get -y update
129-
apt-get -y install fortune cowsay lolcat
13040

131-
%environment
132-
export LC_ALL=C
133-
export PATH=/usr/games:$PATH
134-
135-
%runscript
136-
fortune | cowsay | lolcat
137-
```
138-
139-
You can do so with the following command.
41+
### Build a container from a Singularity recipe
42+
Given a Singularity Recipe called `Singularity`:
14043

14144
```
14245
$ sudo singularity build lolcow.simg Singularity
14346
```
14447

145-
The command requires `sudo` just as installing software on your local machine requires root privileges.
146-
147-
### `--force`
148-
You can build into the same container multiple times (though the results may be unpredictable and it is generally better to delete your container and start from scratch).
149-
150-
By default if you build into an existing container, the `build` command will skip the steps involved in adding a new base. You can override this default with the `--force` option requiring that a new base OS is bootstrapped into the existing container. This behavior does not delete the existing OS, it just adds the new OS on top of the existing one.
151-
152-
Use care with this option: you may get results that you did not expect.
153-
154-
### `--section`
155-
If you only want to build a single section of your Singularity recipe file use the `--section` option. For instance, if you have edited the `%environment` section of a long Singularity recipe and don't want to completely re-build the container, you could re-build only the `%environment` section like so:
156-
157-
```
158-
$ sudo singularity build --section environment image.simg Singularity
159-
```
160-
161-
Under normal build conditions, the Singularity recipe file is saved into a container's meta-data so that there is a record showing how the container was built. Using the `--section` option may render this meta-data useless, so use care if you value reproducibility.
162-
163-
### `--notest`
164-
If you don't want to run the `%test` section during the container build, you can skip it with the `--notest` option. For instance, maybe you are building a container intended to run in a production environment with GPUs. But perhaps your local build resource does not have GPUs. You want to include a `%test` section that runs a short validation but you don't want your build to exit with an error because it cannot find a GPU on your system.
165-
166-
```
167-
$ sudo singularity build GPU.simg --notest Singularity
168-
```
169-
170-
### `--checks`
171-
Checks are a new feature (in 2.4) that offer an easy way for an admin to define a security (or any other kind of check) to be run on demand for a Singularity image. They are defined (and run) via different tags.
172-
173-
```
174-
CHECKS OPTIONS:
175-
-c|--checks enable checks
176-
-t|--tag specify a check tag (not default)
177-
-l|--low Specify low threshold (all checks, default)
178-
-m|--med Perform medium and high checks
179-
-h|--high Perform only checks at level high
180-
```
181-
182-
When you add the `--checks` option along with applicable tags to the `build` command Singularity will run the desired checks on your container at build time. See `singularity check --help` for available tags.
183-
184-
185-
## More Build topics
186-
- If you want to **customize the cache location** (where Docker layers are downloaded on your system), specify Docker credentials, or any custom tweaks to your build environment, see <a href="/build-environment">build environment</a>.
187-
- If you want to make internally **modular containers**, check out <a href="http://containers-ftw.org/apps/examples/tutorials/getting-started" target="_blank">this post</a>.
188-
- If you want to **build your containers** on Singularity Hub, (because you don't have root access on a Linux machine or want to host your container on the cloud) check out [this guide](https://github.com/singularityhub/singularityhub.github.io/wiki).
189-
19048
<script>
19149
// Without this, pagination links to exec under repeated build section
19250
$(document).ready(function() {

pages/docs/user-docs/action-run.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ When you first create a container, the runscript is defined using the following
5959
4. If the user has not defined a runscript and the Docker container doesn't have an `ENTRYPOINT`, we look for `CMD`, even if the user hasn't asked for it.
6060
5. If the user has not deifned a runscript, and there is no `ENTRYPOINT` or `CMD` (or we aren't importing Docker at all) then we default to `/bin/bash`
6161

62-
Here is how you would define the runscript section when you [build](/docs-build) an image:
62+
Here is how you would define the runscript section when you [build](/docs-build-container) an image:
6363

6464
```bash
6565
Bootstrap: docker

0 commit comments

Comments
 (0)