1apptainer(1)                                                      apptainer(1)
2
3
4

NAME

6       apptainer-build - Build an Apptainer image
7
8
9

SYNOPSIS

11       apptainer build [local options...]
12
13
14

DESCRIPTION

16       IMAGE PATH:
17
18
19       When  Apptainer  builds  the container, output can be one of a few for‐
20       mats:
21
22
23                default:    The compressed Apptainer read only image format (default)
24                sandbox:    This is a read-write container within a directory structure
25
26
27
28       note: It is a common workflow to use the "sandbox" mode for development
29       of the
30         container, and then build it as a default Apptainer image for produc‐
31       tion
32         use. The default format is immutable.
33
34
35       BUILD SPEC:
36
37
38       The build spec target is a definition (def) file, local image,  or  URI
39       that can
40         be  used  to  create  an Apptainer container. Several different local
41       target
42         formats exist:
43
44
45                def file  : This is a recipe for building a container (examples below)
46                directory:  A directory structure containing a (ch)root file system
47                image:      A local image on your machine (will convert to sif if
48                            it is legacy format)
49
50
51
52       Targets can also be remote and defined by a URI of the  following  for‐
53       mats:
54
55
56                library://  an image library (no default)
57                docker://   a Docker/OCI registry (default Docker Hub)
58                shub://     an Apptainer registry (default Singularity Hub)
59                oras://     an OCI registry that holds SIF files using ORAS
60
61
62
63

OPTIONS

65       -B,  --bind=[]      a user-bind path specification. spec has the format
66       src[:dest[:opts]],where src and dest are outside and inside  paths.  If
67       dest is not given,it is set equal to src. Mount options ('opts') may be
68       specified as 'ro'(read-only) or 'rw'  (read/write,  which  is  the  de‐
69       fault).Multiple bind paths can be given by a comma separated list.
70
71
72       --disable-cache[=false]      do not use cache or create cache
73
74
75       --docker-login[=false]      login to a Docker Repository interactively
76
77
78       -e, --encrypt[=false]      build an image with an encrypted file system
79
80
81       -f,  --fakeroot[=false]       build  with  the appearance of running as
82       root (default when building from a definition file unprivileged)
83
84
85       --fix-perms[=false]      ensure owner has rwX permissions on  all  con‐
86       tainer content for oci/docker sources
87
88
89       -F, --force[=false]      overwrite an image file if it exists
90
91
92       -h, --help[=false]      help for build
93
94
95       --json[=false]      interpret build definition as JSON
96
97
98       --library=""      container Library URL
99
100
101       --mount=[]       a mount specification e.g. 'type=bind,source=/opt,des‐
102       tination=/hostopt'.
103
104
105       --no-cleanup[=false]      do NOT clean up bundle  after  failed  build,
106       can be helpful for debugging
107
108
109       --no-https[=false]      use http instead of https for docker:// oras://
110       and library:///... URIs
111
112
113       -T, --notest[=false]      build without running tests in %test section
114
115
116       --nv[=false]      inject host Nvidia libraries during  build  for  post
117       and test sections
118
119
120       --nvccli[=false]       use  nvidia-container-cli for GPU setup (experi‐
121       mental)
122
123
124       --passphrase[=false]      prompt for an encryption passphrase
125
126
127       --pem-path=""      enter an path to a PEM formatted RSA key for an  en‐
128       crypted container
129
130
131       --rocm[=false]       inject  host  Rocm libraries during build for post
132       and test sections
133
134
135       -s, --sandbox[=false]      build image as sandbox format (chroot direc‐
136       tory structure)
137
138
139       --section=[all]       only  run  specific section(s) of deffile (setup,
140       post, files, environment, test, labels, none)
141
142
143       -u, --update[=false]      run definition over existing container (skips
144       header)
145
146
147       --userns[=false]      build without using setuid even if available
148
149
150       --writable-tmpfs[=false]       during the %test section, makes the file
151       system accessible as read-write with non persistent data (with  overlay
152       support only)
153
154
155

EXAMPLE

157                DEF FILE BASE OS:
158
159                    Library:
160                        Bootstrap: library
161                        From: debian:9
162
163                    Docker:
164                        Bootstrap: docker
165                        From: tensorflow/tensorflow:latest
166                        IncludeCmd: yes # Use the CMD as runscript instead of ENTRYPOINT
167
168                    Singularity Hub:
169                        Bootstrap: shub
170                        From: singularityhub/centos
171
172                    YUM/RHEL:
173                        Bootstrap: yum
174                        OSVersion: 7
175                        MirrorURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/x86_64/
176                        Include: yum
177
178                    Debian/Ubuntu:
179                        Bootstrap: debootstrap
180                        OSVersion: trusty
181                        MirrorURL: http://us.archive.ubuntu.com/ubuntu/
182
183                    Local Image:
184                        Bootstrap: localimage
185                        From: /home/dave/starter.img
186
187                    Scratch:
188                        Bootstrap: scratch # Populate the container with a minimal rootfs in %setup
189
190                DEFFILE SECTIONS:
191
192                The following sections are presented in the order of processing, with the exception
193                that labels and environment can also be manipulated in %post.
194
195                    %pre
196                        echo "This is a scriptlet that will be executed on the host, as root before"
197                        echo "the container has been bootstrapped. This section is not commonly used."
198
199                    %setup
200                        echo "This is a scriptlet that will be executed on the host, as root, after"
201                        echo "the container has been bootstrapped. To install things into the container"
202                        echo "reference the file system location with $APPTAINER_ROOTFS."
203
204                    %files
205                        /path/on/host/file.txt /path/on/container/file.txt
206                        relative_file.txt /path/on/container/relative_file.txt
207
208                    %post
209                        echo "This scriptlet section will be executed from within the container after"
210                        echo "the bootstrap/base has been created and setup."
211
212                    %environment
213                        LUKE=goodguy
214                        VADER=badguy
215                        HAN=someguy
216                        export HAN VADER LUKE
217
218                    %test
219                        echo "Define any test commands that should be executed after container has been"
220                        echo "built. This scriptlet will be executed from within the running container"
221                        echo "as the root user. Pay attention to the exit/return value of this scriptlet"
222                        echo "as any non-zero exit code will be assumed as failure."
223                        exit 0
224
225                    %runscript
226                        echo "Define actions for the container to be executed with the run command or"
227                        echo "when container is executed."
228
229                    %startscript
230                        echo "Define actions for container to perform when started as an instance."
231
232                    %labels
233                        HELLO MOTO
234                        KEY VALUE
235
236                    %help
237                        This is a text file to be displayed with the run-help command.
238
239                COMMANDS:
240
241                    Build a sif file from an Apptainer recipe file:
242                        $ apptainer build /tmp/debian0.sif /path/to/debian.def
243
244                    Build a sif image from the Library:
245                        $ apptainer build /tmp/debian1.sif library://debian:latest
246
247                    Build a base sandbox from DockerHub, make changes to it, then build sif
248                        $ apptainer build --sandbox /tmp/debian docker://debian:latest
249                        $ apptainer exec --writable /tmp/debian apt-get install python
250                        $ apptainer build /tmp/debian2.sif /tmp/debian
251
252
253
254

SEE ALSO

256       apptainer(1)
257
258
259

HISTORY

261       10-Jan-2023 Auto generated by spf13/cobra
262
263
264
265Auto generated by spf13/cobra      Jan 2023                       apptainer(1)
Impressum