You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/software/containers.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ For more information see the [Apptainer Quick Start guide](https://apptainer.org
81
81
82
82
### Download Pre-built Containers
83
83
84
-
Many software packages already have containers built by developers. These containers are available from external sites such as Docker Hub or ghcr.io. With apptainer you can use the `pull`or `build` commands to download containers.
84
+
Many software packages already have containers built by developers that you can download with the `pull` or `build` commands. These containers are available from external sites such as the [Container Library](https://cloud.sylabs.io/library){:target="_blank"} or [Docker Hub](https://hub.docker.com/){:target="_blank"}.
85
85
86
86
The `apptainer pull` command will download a OCI image from a remote repository, combining the layers to a usable SIF image.
87
87
@@ -101,7 +101,7 @@ $ ./lolcow_latest.sif
101
101
|| ||
102
102
```
103
103
104
-
The `apptainer build` command can also be used to download existing containers. The `build` command has many more uses for building containers from scratch or converting formats, which we cover later. For the purpose of downloading a pre-built container, `build` differs from `pull` by converting the image to the latest Apptainer image format after downloading it. Further, `build` allows for custom naming of the downloaded container.
104
+
The `build` command has many more uses for building containers from scratch or converting formats, which we cover later. For the purpose of downloading a pre-built container, `build` differs from `pull` by converting the image to the latest Apptainer image format after downloading it. Further, `build` allows for custom naming of the downloaded container.
Because these containers are already built, they are immutable. So, you can run things but not install things inside them. To do this, you would build a container, which is explained in the next section.
123
+
122
124
### Build a Container
123
125
124
126
The `build` command is used to create new containers either from scratch or based on existing containers. It can also used to convert between container formats. As an example, we'll discuss the process of building custom Python container from scratch.
@@ -127,7 +129,7 @@ Please see the [Apptainer docs](https://apptainer.org/docs/user/1.3/build_a_cont
127
129
128
130
#### Definition File
129
131
130
-
First we write a definition file for the new container. A definition file defines the container build process including software installation, runtime functionality, etc. This file can be named how you like, but it is recommended to denote definition files with the `.def` extension. We will call our definition file `py_container.def`.
132
+
First we write a definition file for the new container. A definition file defines the container build process including software installation, runtime functionality, etc. This file can be named how you like, but it is recommended to denote definition files with the `.def` extension. We will call our definition file `py_container.def`. See below for an explanation of each section.
131
133
132
134
=== "py_container.def"
133
135
@@ -136,17 +138,13 @@ Bootstrap: docker
136
138
From: ubuntu:20.04
137
139
138
140
%help
139
-
# Add information describing your container.
140
-
This container includes Python.
141
+
This container includes Python.
141
142
142
143
%environment
143
-
# Set useful environment variables here. This section is used only at runtime, not during build.
# Add build commands here. These commands are only run at build time.
149
-
150
148
# Create useful bind points for needed file systems. The following are set by default in RCC and should always be included for containers used in RCC.
151
149
mkdir -p /scratch /hpc
152
150
@@ -178,8 +176,24 @@ This container includes Python.
178
176
/opt/python/bin/python --version
179
177
```
180
178
179
+
As you can see in the previous example, a definition file has two parts. First is the header, which contains information about the base operating system for the container. `Bootstrap` is the first keyword and it's mandatory. It will specify the bootstrap agent. The most common ones are: `library`, `docker`, `shub`, or `localimage`. When using `library` as bootstrap agent, the next keyword must be `From`, followed by the operating system and the version. For example, `From: ubuntu:22.04`.
180
+
181
+
The second part of a definition file is the sections, which execute commands at different times while the container is built or run. All sections are optional. The following table explains them in detail:
182
+
183
+
| Section | Explanation |
184
+
| --- | --- |
185
+
|`%files`| Use this section to copy files from the host into the container. Never copy files into /home, /tmp, or any other directories that are bound at runtime. |
186
+
|`%environment`| Specify variables that will be set **at run** time in this section (NOT available when building the container). Variables set here are global (available to all apps). |
187
+
|`%post`| In this section you can: specify variables that will be set **at build time**, download files from the internet with tools like git and wget, install new software and libraries, write configuration files, create new directories. Never install things into /home, /tmp, or any other directories that are bound at runtime. |
188
+
|`%runscript`| This section is executed when the container is run via the `apptainer run` command or by executing the container directly as a command. Any arguments passed to the container will be processed in this section. We can use here variables set in`%environment` or `%post`. |
189
+
|`%test`| This section runs at the end of the build process to validate the container using a method of your choice. |
190
+
|`%labels`| You can add metadata in this section with name-value format such as `Author Me` or `Version v1.0`. |
191
+
|`%help`| Use this section to explain to the user how to interact with the container. |
192
+
181
193
Full documentation of definition files at [Apptainer Docs](https://apptainer.org/docs/user/1.3/definition_files.html){:target="_blank"}.
182
194
195
+
Examples of definition files: [Apptainer examples](https://github.com/apptainer/apptainer/tree/main/examples){:target="_blank"}.
0 commit comments