1podman-build(1)() podman-build(1)()
2
3
4
6 podman-build - Build a container image using a Containerfile
7
8
10 podman build [options] [context]
11
12
13 podman image build [options] [context]
14
15
17 podman build Builds an image using instructions from one or more Con‐
18 tainerfiles or Dockerfiles and a specified build context directory. A
19 Containerfile uses the same syntax as a Dockerfile internally. For this
20 document, a file referred to as a Containerfile can be a file named ei‐
21 ther 'Containerfile' or 'Dockerfile'.
22
23
24 The build context directory can be specified as the http(s) URL of an
25 archive, git repository or Containerfile.
26
27
28 If no context directory is specified, then Podman will assume the cur‐
29 rent working directory as the build context, which should contain the
30 Containerfile.
31
32
33 Containerfiles ending with a ".in" suffix will be preprocessed via
34 CPP(1). This can be useful to decompose Containerfiles into several
35 reusable parts that can be used via CPP's #include directive. Notice,
36 a Containerfile.in file can still be used by other tools when manually
37 preprocessing them via cpp -E.
38
39
40 When the URL is an archive, the contents of the URL is downloaded to a
41 temporary location and extracted before execution.
42
43
44 When the URL is a Containerfile, the Containerfile is downloaded to a
45 temporary location.
46
47
48 When a Git repository is set as the URL, the repository is cloned lo‐
49 cally and then set as the context.
50
51
52 NOTE: podman build uses code sourced from the Buildah project to build
53 container images. This Buildah code creates Buildah containers for the
54 RUN options in container storage. In certain situations, when the pod‐
55 man build crashes or users kill the podman build process, these exter‐
56 nal containers can be left in container storage. Use the podman ps
57 --all --storage command to see these containers. External containers
58 can be removed with the podman rm --storage command.
59
60
61 podman buildx build command is an alias of podman build. Not all
62 buildx build features are available in Podman. The buildx build option
63 is provided for scripting compatibility.
64
65
67 --add-host=host
68 Add a custom host-to-IP mapping (host:ip)
69
70
71 Add a line to /etc/hosts. The format is hostname:ip. The --add-host op‐
72 tion can be set multiple times. Conflicts with the --no-hosts option.
73
74
75 --all-platforms
76 Instead of building for a set of platforms specified using the --plat‐
77 form option, inspect the build's base images, and build for all of the
78 platforms for which they are all available. Stages that use scratch as
79 a starting point can not be inspected, so at least one non-scratch
80 stage must be present for detection to work usefully.
81
82
83 --annotation=annotation
84 Add an image annotation (e.g. annotation=value) to the image metadata.
85 Can be used multiple times.
86
87
88 Note: this information is not present in Docker image formats, so it is
89 discarded when writing images in Docker formats.
90
91
92 --arch=arch
93 Set the architecture of the image to be built, and that of the base im‐
94 age to be pulled, if the build uses one, to the provided value instead
95 of using the architecture of the build host. (Examples: arm, arm64,
96 386, amd64, ppc64le, s390x)
97
98
99 --authfile=path
100 Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/contain‐
101 ers/auth.json, which is set using podman login. If the authorization
102 state is not found there, $HOME/.docker/config.json is checked, which
103 is set using docker login.
104
105
106 Note: You can also override the default path of the authentication file
107 by setting the REGISTRY_AUTH_FILE environment variable. export REG‐
108 ISTRY_AUTH_FILE=path
109
110
111 --build-arg=arg=value
112 Specifies a build argument and its value, which will be interpolated in
113 instructions read from the Containerfiles in the same way that environ‐
114 ment variables are, but which will not be added to environment variable
115 list in the resulting image's configuration.
116
117
118 --cache-from
119 Images to utilize as potential cache sources. Podman does not currently
120 support caching so this is a NOOP. (This option is not available with
121 the remote Podman client, including Mac and Windows (excluding WSL2)
122 machines)
123
124
125 --cap-add=CAP_xxx
126 When executing RUN instructions, run the command specified in the in‐
127 struction with the specified capability added to its capability set.
128 Certain capabilities are granted by default; this option can be used to
129 add more.
130
131
132 --cap-drop=CAP_xxx
133 When executing RUN instructions, run the command specified in the in‐
134 struction with the specified capability removed from its capability
135 set. The CAP_AUDIT_WRITE, CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_FOWNER,
136 CAP_FSETID, CAP_KILL, CAP_MKNOD, CAP_NET_BIND_SERVICE, CAP_SETFCAP,
137 CAP_SETGID, CAP_SETPCAP, CAP_SETUID, and CAP_SYS_CHROOT capabilities
138 are granted by default; this option can be used to remove them.
139
140
141 If a capability is specified to both the --cap-add and --cap-drop op‐
142 tions, it will be dropped, regardless of the order in which the options
143 were given.
144
145
146 --cert-dir=path
147 Use certificates at path (*.crt, *.cert, *.key) to connect to the reg‐
148 istry. (Default: /etc/containers/certs.d) Please refer to containers-
149 certs.d(5) for details. (This option is not available with the remote
150 Podman client, including Mac and Windows (excluding WSL2) machines)
151
152
153 --cgroup-parent=path
154 Path to cgroups under which the cgroup for the container will be cre‐
155 ated. If the path is not absolute, the path is considered to be rela‐
156 tive to the cgroups path of the init process. Cgroups will be created
157 if they do not already exist.
158
159
160 --cgroupns=how
161 Sets the configuration for cgroup namespaces when handling RUN instruc‐
162 tions. The configured value can be "" (the empty string) or "private"
163 to indicate that a new cgroup namespace should be created, or it can be
164 "host" to indicate that the cgroup namespace in which buildah itself is
165 being run should be reused.
166
167
168 --compress
169 This option is added to be aligned with other containers CLIs. Podman
170 doesn't communicate with a daemon or a remote server. Thus, compress‐
171 ing the data before sending it is irrelevant to Podman. (This option is
172 not available with the remote Podman client, including Mac and Windows
173 (excluding WSL2) machines)
174
175
176 --cpu-period=limit
177 Set the CPU period for the Completely Fair Scheduler (CFS), which is a
178 duration in microseconds. Once the container's CPU quota is used up, it
179 will not be scheduled to run until the current period ends. Defaults to
180 100000 microseconds.
181
182
183 On some systems, changing the CPU limits may not be allowed for non-
184 root users. For more details, see https://github.com/containers/pod‐
185 man/blob/main/troubleshooting.md#26-running-containers-with-cpu-limits-
186 fails-with-a-permissions-error
187
188
189 --cpu-quota=limit
190 Limit the CPU Completely Fair Scheduler (CFS) quota.
191
192
193 Limit the container's CPU usage. By default, containers run with the
194 full CPU resource. The limit is a number in microseconds. If you pro‐
195 vide a number, the container will be allowed to use that much CPU time
196 until the CPU period ends (controllable via --cpu-period).
197
198
199 On some systems, changing the CPU limits may not be allowed for non-
200 root users. For more details, see https://github.com/containers/pod‐
201 man/blob/main/troubleshooting.md#26-running-containers-with-cpu-limits-
202 fails-with-a-permissions-error
203
204
205 --cpu-shares, -c=shares
206 CPU shares (relative weight)
207
208
209 By default, all containers get the same proportion of CPU cycles. This
210 proportion can be modified by changing the container's CPU share
211 weighting relative to the weighting of all other running containers.
212
213
214 To modify the proportion from the default of 1024, use the --cpu-shares
215 option to set the weighting to 2 or higher.
216
217
218 The proportion will only apply when CPU-intensive processes are run‐
219 ning. When tasks in one container are idle, other containers can use
220 the left-over CPU time. The actual amount of CPU time will vary depend‐
221 ing on the number of containers running on the system.
222
223
224 For example, consider three containers, one has a cpu-share of 1024 and
225 two others have a cpu-share setting of 512. When processes in all three
226 containers attempt to use 100% of CPU, the first container would re‐
227 ceive 50% of the total CPU time. If you add a fourth container with a
228 cpu-share of 1024, the first container only gets 33% of the CPU. The
229 remaining containers receive 16.5%, 16.5% and 33% of the CPU.
230
231
232 On a multi-core system, the shares of CPU time are distributed over all
233 CPU cores. Even if a container is limited to less than 100% of CPU
234 time, it can use 100% of each individual CPU core.
235
236
237 For example, consider a system with more than three cores. If you start
238 one container {C0} with -c=512 running one process, and another con‐
239 tainer {C1} with -c=1024 running two processes, this can result in the
240 following division of CPU shares:
241
242
243 PID container CPU CPU share
244 100 {C0} 0 100% of CPU0
245 101 {C1} 1 100% of CPU1
246 102 {C1} 2 100% of CPU2
247
248
249
250 --cpuset-cpus=num
251 CPUs in which to allow execution (0-3, 0,1)
252
253
254 --cpuset-mems=nodes
255 Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effec‐
256 tive on NUMA systems.
257
258
259 If you have four memory nodes on your system (0-3), use --cpuset-
260 mems=0,1 then processes in your container will only use memory from the
261 first two memory nodes.
262
263
264 --creds=creds
265 The [username[:password]] to use to authenticate with the registry if
266 required. If one or both values are not supplied, a command line
267 prompt will appear and the value can be entered. The password is en‐
268 tered without echo.
269
270
271 --decryption-key=key[:passphrase]
272 The [key[:passphrase]] to be used for decryption of images. Key can
273 point to keys and/or certificates. Decryption will be tried with all
274 keys. If the key is protected by a passphrase, it is required to be
275 passed in the argument and omitted otherwise.
276
277
278 --device=host-device[:container-device][:permissions]
279 Add a host device to the container. Optional permissions parameter can
280 be used to specify device permissions, it is combination of r for read,
281 w for write, and m for mknod(2).
282
283
284 Example: --device=/dev/sdc:/dev/xvdc:rwm.
285
286
287 Note: if _hostdevice is a symbolic link then it will be resolved first.
288 The container will only store the major and minor numbers of the host
289 device.
290
291
292 Note: if the user only has access rights via a group, accessing the de‐
293 vice from inside a rootless container will fail. The crun(1) runtime
294 offers a workaround for this by adding the option
295
296
297 --annotation run.oci.keep_original_groups=1.
298 --disable-compression, -D
299 Don't compress filesystem layers when building the image unless it is
300 required by the location where the image is being written. This is the
301 default setting, because image layers are compressed automatically when
302 they are pushed to registries, and images being written to local stor‐
303 age would only need to be decompressed again to be stored. Compression
304 can be forced in all cases by specifying --disable-compression=false.
305
306
307 --disable-content-trust
308 This is a Docker specific option to disable image verification to a
309 container registry and is not supported by Podman. This option is a
310 NOOP and provided solely for scripting compatibility. (This option is
311 not available with the remote Podman client, including Mac and Windows
312 (excluding WSL2) machines)
313
314
315 --dns=dns
316 Set custom DNS servers to be used during the build.
317
318
319 This option can be used to override the DNS configuration passed to the
320 container. Typically this is necessary when the host DNS configuration
321 is invalid for the container (e.g., 127.0.0.1). When this is the case
322 the --dns option is necessary for every run.
323
324
325 The special value none can be specified to disable creation of /etc/re‐
326 solv.conf in the container by Podman. The /etc/resolv.conf file in the
327 image will be used without changes.
328
329
330 --dns-option=option
331 Set custom DNS options to be used during the build.
332
333
334 --dns-search=domain
335 Set custom DNS search domains to be used during the build.
336
337
338 --env env[=value]
339 Add a value (e.g. env=value) to the built image. Can be used multiple
340 times. If neither = nor a *value* are specified, but env is set in the
341 current environment, the value from the current environment will be
342 added to the image. To remove an environment variable from the built
343 image, use the --unsetenv option.
344
345
346 --file, -f=Containerfile
347 Specifies a Containerfile which contains instructions for building the
348 image, either a local file or an http or https URL. If more than one
349 Containerfile is specified, FROM instructions will only be accepted
350 from the first specified file.
351
352
353 If a build context is not specified, and at least one Containerfile is
354 a local file, the directory in which it resides will be used as the
355 build context.
356
357
358 If you specify -f -, the Containerfile contents will be read from
359 stdin.
360
361
362 --force-rm
363 Always remove intermediate containers after a build, even if the build
364 fails (default true).
365
366
367 --format
368 Control the format for the built image's manifest and configuration
369 data. Recognized formats include oci (OCI image-spec v1.0, the de‐
370 fault) and docker (version 2, using schema format 2 for the manifest).
371
372
373 Note: You can also override the default format by setting the BUIL‐
374 DAH_FORMAT environment variable. export BUILDAH_FORMAT=docker
375
376
377 --from
378 Overrides the first FROM instruction within the Containerfile. If
379 there are multiple FROM instructions in a Containerfile, only the first
380 is changed.
381
382
383 --help, -h
384 Print usage statement
385
386
387 --http-proxy
388 Pass through HTTP Proxy environment variables.
389
390
391 --identity-label
392 Adds default identity label io.buildah.version if set. (default true).
393
394
395 --ignorefile
396 Path to an alternative .containerignore file.
397
398
399 --iidfile=ImageIDfile
400 Write the built image's ID to the file. When --platform is specified
401 more than once, attempting to use this option will trigger an error.
402
403
404 --ipc=how
405 Sets the configuration for IPC namespaces when handling RUN instruc‐
406 tions. The configured value can be "" (the empty string) or "con‐
407 tainer" to indicate that a new IPC namespace should be created, or it
408 can be "host" to indicate that the IPC namespace in which podman itself
409 is being run should be reused, or it can be the path to an IPC name‐
410 space which is already in use by another process.
411
412
413 --isolation=type
414 Controls what type of isolation is used for running processes as part
415 of RUN instructions. Recognized types include oci (OCI-compatible run‐
416 time, the default), rootless (OCI-compatible runtime invoked using a
417 modified configuration and its --rootless option enabled, with --no-
418 new-keyring --no-pivot added to its create invocation, with network and
419 UTS namespaces disabled, and IPC, PID, and user namespaces enabled; the
420 default for unprivileged users), and chroot (an internal wrapper that
421 leans more toward chroot(1) than container technology).
422
423
424 Note: You can also override the default isolation type by setting the
425 BUILDAH_ISOLATION environment variable. export BUILDAH_ISOLATION=oci
426
427
428 --jobs=number
429 Run up to N concurrent stages in parallel. If the number of jobs is
430 greater than 1, stdin will be read from /dev/null. If 0 is specified,
431 then there is no limit in the number of jobs that run in parallel.
432
433
434 --label=label
435 Add an image label (e.g. label=value) to the image metadata. Can be
436 used multiple times.
437
438
439 Users can set a special LABEL io.containers.capabilities=CAP1,CAP2,CAP3
440 in a Containerfile that specifies the list of Linux capabilities re‐
441 quired for the container to run properly. This label specified in a
442 container image tells Podman to run the container with just these capa‐
443 bilities. Podman launches the container with just the specified capa‐
444 bilities, as long as this list of capabilities is a subset of the de‐
445 fault list.
446
447
448 If the specified capabilities are not in the default set, Podman will
449 print an error message and will run the container with the default ca‐
450 pabilities.
451
452
453 --layers
454 Cache intermediate images during the build process (Default is true).
455
456
457 Note: You can also override the default value of layers by setting the
458 BUILDAH_LAYERS environment variable. export BUILDAH_LAYERS=true
459
460
461 --logfile=filename
462 Log output which would be sent to standard output and standard error to
463 the specified file instead of to standard output and standard error.
464
465
466 --manifest manifest
467 Name of the manifest list to which the image will be added. Creates the
468 manifest list if it does not exist. This option is useful for building
469 multi architecture images.
470
471
472 --memory, -m=LIMIT
473 Memory limit (format: <number>[<unit>], where unit = b (bytes), k
474 (kibibytes), m (mebibytes), or g (gibibytes))
475
476
477 Allows you to constrain the memory available to a container. If the
478 host supports swap memory, then the -m memory setting can be larger
479 than physical RAM. If a limit of 0 is specified (not using -m), the
480 container's memory is not limited. The actual limit may be rounded up
481 to a multiple of the operating system's page size (the value would be
482 very large, that's millions of trillions).
483
484
485 --memory-swap=LIMIT
486 A limit value equal to memory plus swap. Must be used with the -m
487 (--memory) option. The swap LIMIT should always be larger than -m
488 (--memory) value. By default, the swap LIMIT will be set to double the
489 value of --memory.
490
491
492 The format of LIMIT is <number>[<unit>]. Unit can be b (bytes), k
493 (kibibytes), m (mebibytes), or g (gibibytes). If you don't specify a
494 unit, b is used. Set LIMIT to -1 to enable unlimited swap.
495
496
497 --network=mode, --net
498 Sets the configuration for network namespaces when handling RUN in‐
499 structions.
500
501
502 Valid mode values are:
503
504
505 • none: no networking.
506
507 • host: use the Podman host network stack. Note: the host mode
508 gives the container full access to local system services such
509 as D-bus and is therefore considered insecure.
510
511 • ns:path: path to a network namespace to join.
512
513 • private: create a new namespace for the container (default)
514
515 • <network name|ID>: Join the network with the given name or ID,
516 e.g. use --network mynet to join the network with the name
517 mynet. Only supported for rootful users.
518
519
520
521 --no-cache
522 Do not use existing cached images for the container build. Build from
523 the start with a new set of cached layers.
524
525
526 --no-hosts
527 Do not create /etc/hosts for the container. By default, Podman will
528 manage /etc/hosts, adding the container's own IP address and any hosts
529 from --add-host. --no-hosts disables this, and the image's /etc/hosts
530 will be preserved unmodified. This option conflicts with --add-host.
531
532
533 --os=string
534 Set the OS of the image to be built, and that of the base image to be
535 pulled, if the build uses one, instead of using the current operating
536 system of the build host.
537
538
539 --os-feature feature
540 Set the name of a required operating system feature for the image which
541 will be built. By default, if the image is not based on scratch, the
542 base image's required OS feature list is kept, if the base image speci‐
543 fied any. This option is typically only meaningful when the image's OS
544 is Windows.
545
546
547 If feature has a trailing -, then the feature is removed from the set
548 of required features which will be listed in the image.
549
550
551 --os-version version
552 Set the exact required operating system version for the image which
553 will be built. By default, if the image is not based on scratch, the
554 base image's required OS version is kept, if the base image specified
555 one. This option is typically only meaningful when the image's OS is
556 Windows, and is typically set in Windows base images, so using this op‐
557 tion is usually unnecessary.
558
559
560 --output, -o=""
561 Output destination (format: type=local,dest=path)
562
563
564 The --output (or -o) option extends the default behavior of building a
565 container image by allowing users to export the contents of the image
566 as files on the local filesystem, which can be useful for generating
567 local binaries, code generation, etc. (This option is not available
568 with the remote Podman client, including Mac and Windows (excluding
569 WSL2) machines)
570
571
572 The value for --output is a comma-separated sequence of key=value
573 pairs, defining the output type and options.
574
575
576 Supported keys are: - dest: Destination path for exported output. Valid
577 value is absolute or relative path, - means the standard output. -
578 type: Defines the type of output to be used. Valid values is documented
579 below.
580
581
582 Valid type values are: - local: write the resulting build files to a
583 directory on the client-side. - tar: write the resulting files as a
584 single tarball (.tar).
585
586
587 If no type is specified, the value defaults to local. Alternatively,
588 instead of a comma-separated sequence, the value of --output can be
589 just a destination (in the **dest** format) (e.g.--output some-
590 path,--output -) where--output some-pathis treated as if **type=local**
591 and--output -` is treated as if type=tar.
592
593
594 --pid=pid
595 Sets the configuration for PID namespaces when handling RUN instruc‐
596 tions. The configured value can be "" (the empty string) or "con‐
597 tainer" to indicate that a new PID namespace should be created, or it
598 can be "host" to indicate that the PID namespace in which podman itself
599 is being run should be reused, or it can be the path to a PID namespace
600 which is already in use by another process.
601
602
603 --platform="OS/ARCH[/VARIANT][,...]"
604 Set the OS/ARCH of the built image (and its base image, if your build
605 uses one) to the provided value instead of using the current operating
606 system and architecture of the host (for example linux/arm). If --plat‐
607 form is set, then the values of the --arch, --os, and --variant options
608 will be overridden.
609
610
611 The --platform option can be specified more than once, or given a
612 comma-separated list of values as its argument. When more than one
613 platform is specified, the --manifest option should be used instead of
614 the --tag option.
615
616
617 OS/ARCH pairs are those used by the Go Programming Language. In sev‐
618 eral cases the ARCH value for a platform differs from one produced by
619 other tools such as the arch command. Valid OS and architecture name
620 combinations are listed as values for $GOOS and $GOARCH at
621 https://golang.org/doc/install/source#environment, and can also be
622 found by running go tool dist list.
623
624
625 While podman build is happy to use base images and build images for any
626 platform that exists, RUN instructions will not be able to succeed
627 without the help of emulation provided by packages like qemu-user-
628 static.
629
630
631 --pull
632 When the option is enabled or set explicitly to true (with --pull=true)
633 pull the image from the first registry it is found in as listed in reg‐
634 istries.conf. Raise an error if the image could not be pulled, even if
635 the image is present locally.
636
637
638 If the option is disabled (with --pull=false), pull the image from the
639 registry only if the image is not present locally. Raise an error if
640 the image is not in the registries and not present locally.
641
642
643 If the pull option is set to always (with --pull=always), pull the im‐
644 age from the first registry it is found in as listed in reg‐
645 istries.conf. Raise an error if not found in the registries, even if
646 the image is present locally.
647
648
649 If the pull option is set to missing (with --pull=missing), Pull the
650 image only if it is not present in the local storage. Raise an error
651 if it could neither be found in the local storage or on a registry.
652
653
654 If the pull option is set to never (with --pull=never), Do not pull the
655 image from the registry, use only the local version. Raise an error if
656 the image is not present locally.
657
658
659 --quiet, -q
660 Suppress output messages which indicate which instruction is being pro‐
661 cessed, and of progress when pulling images from a registry, and when
662 writing the output image.
663
664
665 --rm
666 Remove intermediate containers after a successful build (default true).
667
668
669 --runtime=path
670 The path to an alternate OCI-compatible runtime, which will be used to
671 run commands specified by the RUN instruction.
672
673
674 Note: You can also override the default runtime by setting the BUIL‐
675 DAH_RUNTIME environment variable. export BUILDAH_RUNTIME=/usr/lo‐
676 cal/bin/runc
677
678
679 --secret=id=id,src=path
680 Pass secret information to be used in the Containerfile for building
681 images in a safe way that will not end up stored in the final image, or
682 be seen in other stages. The secret will be mounted in the container
683 at the default location of /run/secrets/id.
684
685
686 To later use the secret, use the --mount option in a RUN instruction
687 within a Containerfile:
688
689
690 RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret
691
692
693 --security-opt=option
694 Security Options
695
696
697 • apparmor=unconfined : Turn off apparmor confinement for the
698 container
699
700 • apparmor=your-profile : Set the apparmor confinement profile
701 for the container
702
703 • label=user:USER : Set the label user for the container
704 processes
705
706 • label=role:ROLE : Set the label role for the container
707 processes
708
709 • label=type:TYPE : Set the label process type for the con‐
710 tainer processes
711
712 • label=level:LEVEL : Set the label level for the container
713 processes
714
715 • label=filetype:TYPE : Set the label file type for the con‐
716 tainer files
717
718 • label=disable : Turn off label separation for the con‐
719 tainer
720
721 • no-new-privileges : Not supported
722
723 • seccomp=unconfined : Turn off seccomp confinement for the con‐
724 tainer
725
726 • seccomp=profile.json : White listed syscalls seccomp Json
727 file to be used as a seccomp filter
728
729
730
731 --shm-size=size
732 Size of /dev/shm. The format is <number><unit>. number must be greater
733 than 0. Unit is optional and can be b (bytes), k (kibibytes),
734 m(mebibytes), or g (gibibytes). If you omit the unit, the system uses
735 bytes. If you omit the size entirely, the system uses 64m.
736
737
738 --sign-by=fingerprint
739 Sign the image using a GPG key with the specified FINGERPRINT. (This
740 option is not available with the remote Podman client, including Mac
741 and Windows (excluding WSL2) machines,)
742
743
744 --squash
745 Squash all of the image's new layers into a single new layer; any pre‐
746 existing layers are not squashed.
747
748
749 --squash-all
750 Squash all of the new image's layers (including those inherited from a
751 base image) into a single new layer.
752
753
754 --ssh=default|id[=socket>|[,]
755 SSH agent socket or keys to expose to the build. The socket path can
756 be left empty to use the value of default=$SSH_AUTH_SOCK
757
758
759 To later use the ssh agent, use the --mount option in a RUN instruction
760 within a Containerfile:
761
762
763 RUN --mount=type=ssh,id=id mycmd
764
765
766 --stdin
767 Pass stdin into the RUN containers. Sometime commands being RUN within
768 a Containerfile want to request information from the user. For example
769 apt asking for a confirmation for install. Use --stdin to be able to
770 interact from the terminal during the build.
771
772
773 --tag, -t=imageName
774 Specifies the name which will be assigned to the resulting image if the
775 build process completes successfully. If imageName does not include a
776 registry name, the registry name localhost will be prepended to the im‐
777 age name.
778
779
780 --target=stageName
781 Set the target build stage to build. When building a Containerfile
782 with multiple build stages, --target can be used to specify an interme‐
783 diate build stage by name as the final stage for the resulting image.
784 Commands after the target stage will be skipped.
785
786
787 --timestamp seconds
788 Set the create timestamp to seconds since epoch to allow for determin‐
789 istic builds (defaults to current time). By default, the created time‐
790 stamp is changed and written into the image manifest with every commit,
791 causing the image's sha256 hash to be different even if the sources are
792 exactly the same otherwise. When --timestamp is set, the created time‐
793 stamp is always set to the time specified and therefore not changed,
794 allowing the image's sha256 hash to remain the same. All files commit‐
795 ted to the layers of the image will be created with the timestamp.
796
797
798 --tls-verify
799 Require HTTPS and verify certificates when talking to container reg‐
800 istries (defaults to true). (This option is not available with the re‐
801 mote Podman client, including Mac and Windows (excluding WSL2) ma‐
802 chines)
803
804
805 --ulimit=type=soft-limit[:hard-limit]
806 Specifies resource limits to apply to processes launched when process‐
807 ing RUN instructions. This option can be specified multiple times.
808 Recognized resource types include:
809 "core": maximum core dump size (ulimit -c)
810 "cpu": maximum CPU time (ulimit -t)
811 "data": maximum size of a process's data segment (ulimit -d)
812 "fsize": maximum size of new files (ulimit -f)
813 "locks": maximum number of file locks (ulimit -x)
814 "memlock": maximum amount of locked memory (ulimit -l)
815 "msgqueue": maximum amount of data in message queues (ulimit -q)
816 "nice": niceness adjustment (nice -n, ulimit -e)
817 "nofile": maximum number of open files (ulimit -n)
818 "nproc": maximum number of processes (ulimit -u)
819 "rss": maximum size of a process's (ulimit -m)
820 "rtprio": maximum real-time scheduling priority (ulimit -r)
821 "rttime": maximum amount of real-time execution between blocking
822 syscalls
823 "sigpending": maximum number of pending signals (ulimit -i)
824 "stack": maximum stack size (ulimit -s)
825
826
827 --unsetenv env
828 Unset environment variables from the final image.
829
830
831 --userns=how
832 Sets the configuration for user namespaces when handling RUN instruc‐
833 tions. The configured value can be "" (the empty string) or "con‐
834 tainer" to indicate that a new user namespace should be created, it can
835 be "host" to indicate that the user namespace in which podman itself is
836 being run should be reused, or it can be the path to a user namespace
837 which is already in use by another process.
838
839
840 --userns-gid-map=mapping
841 Directly specifies a GID mapping which should be used to set ownership,
842 at the filesystem level, on the working container's contents. Commands
843 run when handling RUN instructions will default to being run in their
844 own user namespaces, configured using the UID and GID maps.
845
846
847 Entries in this map take the form of one or more triples of a starting
848 in-container GID, a corresponding starting host-level GID, and the num‐
849 ber of consecutive IDs which the map entry represents.
850
851
852 This option overrides the remap-gids setting in the options section of
853 /etc/containers/storage.conf.
854
855
856 If this option is not specified, but a global --userns-gid-map setting
857 is supplied, settings from the global option will be used.
858
859
860 If none of --userns-uid-map-user, --userns-gid-map-group, or --userns-
861 gid-map are specified, but --userns-uid-map is specified, the GID map
862 will be set to use the same numeric values as the UID map.
863
864
865 --userns-gid-map-group=group
866 Specifies that a GID mapping which should be used to set ownership, at
867 the filesystem level, on the working container's contents, can be found
868 in entries in the /etc/subgid file which correspond to the specified
869 group. Commands run when handling RUN instructions will default to be‐
870 ing run in their own user namespaces, configured using the UID and GID
871 maps. If --userns-uid-map-user is specified, but --userns-gid-map-
872 group is not specified, podman will assume that the specified user name
873 is also a suitable group name to use as the default setting for this
874 option.
875
876
877 NOTE: When this option is specified by a rootless user, the specified
878 mappings are relative to the rootless user namespace in the container,
879 rather than being relative to the host as it would be when run rootful.
880
881
882 --userns-uid-map=mapping
883 Directly specifies a UID mapping which should be used to set ownership,
884 at the filesystem level, on the working container's contents. Commands
885 run when handling RUN instructions will default to being run in their
886 own user namespaces, configured using the UID and GID maps.
887
888
889 Entries in this map take the form of one or more triples of a starting
890 in-container UID, a corresponding starting host-level UID, and the num‐
891 ber of consecutive IDs which the map entry represents.
892
893
894 This option overrides the remap-uids setting in the options section of
895 /etc/containers/storage.conf.
896
897
898 If this option is not specified, but a global --userns-uid-map setting
899 is supplied, settings from the global option will be used.
900
901
902 If none of --userns-uid-map-user, --userns-gid-map-group, or --userns-
903 uid-map are specified, but --userns-gid-map is specified, the UID map
904 will be set to use the same numeric values as the GID map.
905
906
907 --userns-uid-map-user=user
908 Specifies that a UID mapping which should be used to set ownership, at
909 the filesystem level, on the working container's contents, can be found
910 in entries in the /etc/subuid file which correspond to the specified
911 user. Commands run when handling RUN instructions will default to be‐
912 ing run in their own user namespaces, configured using the UID and GID
913 maps. If --userns-gid-map-group is specified, but --userns-uid-map-
914 user is not specified, podman will assume that the specified group name
915 is also a suitable user name to use as the default setting for this op‐
916 tion.
917
918
919 NOTE: When this option is specified by a rootless user, the specified
920 mappings are relative to the rootless user namespace in the container,
921 rather than being relative to the host as it would be when run rootful.
922
923
924 --uts=how
925 Sets the configuration for UTS namespaces when handling RUN instruc‐
926 tions. The configured value can be "" (the empty string) or "con‐
927 tainer" to indicate that a new UTS namespace should be created, or it
928 can be "host" to indicate that the UTS namespace in which podman itself
929 is being run should be reused, or it can be the path to a UTS namespace
930 which is already in use by another process.
931
932
933 --variant=""
934 Set the architecture variant of the image to be built, and that of the
935 base image to be pulled, if the build uses one, to the provided value
936 instead of using the architecture variant of the build host.
937
938
939 --volume, -v[=[HOST-DIR:CONTAINER-DIR[:OPTIONS]]]
940 Create a bind mount. If you specify, -v /HOST-DIR:/CONTAINER-DIR, Pod‐
941 man
942 bind mounts /HOST-DIR in the host to /CONTAINER-DIR in the Podman
943 container. (This option is not available with the remote Podman
944 client, including Mac and Windows (excluding WSL2) machines)
945
946
947 The OPTIONS are a comma-separated list and can be: [1] ⟨#Footnote1⟩
948
949
950 • [rw|ro]
951
952 • [z|Z|O]
953
954 • [U]
955
956 • [[r]shared|[r]slave|[r]private]
957
958
959
960 The CONTAINER-DIR must be an absolute path such as /src/docs. The HOST-
961 DIR must be an absolute path as well. Podman bind-mounts the HOST-DIR
962 to the path you specify. For example, if you supply /foo as the host
963 path, Podman copies the contents of /foo to the container filesystem on
964 the host and bind mounts that into the container.
965
966
967 You can specify multiple -v options to mount one or more mounts to a
968 container.
969
970
971 You can add the :ro or :rw suffix to a volume to mount it read-only or
972 read-write mode, respectively. By default, the volumes are mounted
973 read-write. See examples.
974
975
976 Chowning Volume Mounts
977
978
979 By default, Podman does not change the owner and group of source volume
980 directories mounted. When running using user namespaces, the UID and
981 GID inside the namespace may correspond to another UID and GID on the
982 host.
983
984
985 The :U suffix tells Podman to use the correct host UID and GID based on
986 the UID and GID within the namespace, to change recursively the owner
987 and group of the source volume.
988
989
990 Warning use with caution since this will modify the host filesystem.
991
992
993 Labeling Volume Mounts
994
995
996 Labeling systems like SELinux require that proper labels are placed on
997 volume content mounted into a container. Without a label, the security
998 system might prevent the processes running inside the container from
999 using the content. By default, Podman does not change the labels set by
1000 the OS.
1001
1002
1003 To change a label in the container context, you can add either of two
1004 suffixes :z or :Z to the volume mount. These suffixes tell Podman to
1005 relabel file objects on the shared volumes. The z option tells Podman
1006 that two containers share the volume content. As a result, Podman la‐
1007 bels the content with a shared content label. Shared volume labels al‐
1008 low all containers to read/write content. The Z option tells Podman to
1009 label the content with a private unshared label. Only the current con‐
1010 tainer can use a private volume.
1011
1012
1013 Note: Do not relabel system files and directories. Relabeling system
1014 content might cause other confined services on your machine to fail.
1015 For these types of containers, disabling SELinux separation is recom‐
1016 mended. The option --security-opt label=disable disables SELinux sepa‐
1017 ration for the container. For example, if a user wanted to volume
1018 mount their entire home directory into the build containers, they need
1019 to disable SELinux separation.
1020
1021
1022 $ podman build --security-opt label=disable -v $HOME:/home/user .
1023
1024
1025
1026 Overlay Volume Mounts
1027
1028
1029 The :O flag tells Podman to mount the directory from the host as a tem‐
1030 porary storage using the Overlay file system. The RUN command contain‐
1031 ers are allowed to modify contents within the mountpoint and are stored
1032 in the container storage in a separate directory. In Overlay FS terms
1033 the source directory will be the lower, and the container storage di‐
1034 rectory will be the upper. Modifications to the mount point are de‐
1035 stroyed when the RUN command finishes executing, similar to a tmpfs
1036 mount point.
1037
1038
1039 Any subsequent execution of RUN commands sees the original source di‐
1040 rectory content, any changes from previous RUN commands no longer ex‐
1041 ists.
1042
1043
1044 One use case of the overlay mount is sharing the package cache from the
1045 host into the container to allow speeding up builds.
1046
1047
1048 Note:
1049
1050
1051 - Overlay mounts are not currently supported in rootless mode.
1052 - The `O` flag is not allowed to be specified with the `Z` or `z` flags.
1053
1054
1055
1056 Content mounted into the container is labeled with the private label.
1057 On SELinux systems, labels in the source directory needs to be
1058 readable by the container label. If not, SELinux container separation
1059 must be disabled for the container to work.
1060 - Modification of the directory volume mounted into the container
1061 with an overlay mount can cause unexpected failures. It is recommended
1062 that you do not modify the directory until the container finishes run‐
1063 ning.
1064
1065
1066 By default bind mounted volumes are private. That means any mounts done
1067 inside containers will not be visible on the host and vice versa. This
1068 behavior can be changed by specifying a volume mount propagation prop‐
1069 erty.
1070
1071
1072 When the mount propagation policy is set to shared, any mounts com‐
1073 pleted inside the container on that volume will be visible to both the
1074 host and container. When the mount propagation policy is set to slave,
1075 one way mount propagation is enabled and any mounts completed on the
1076 host for that volume will be visible only inside of the container. To
1077 control the mount propagation property of volume use the :[r]shared,
1078 :[r]slave or :[r]private propagation flag. For mount propagation to
1079 work on the source mount point (mount point where source dir is mounted
1080 on) has to have the right propagation properties. For shared volumes,
1081 the source mount point has to be shared. And for slave volumes, the
1082 source mount has to be either shared or slave. [1] ⟨#Footnote1⟩
1083
1084
1085 Use df <source-dir> to determine the source mount and then use findmnt
1086 -o TARGET,PROPAGATION <source-mount-dir> to determine propagation prop‐
1087 erties of source mount, if findmnt utility is not available, the source
1088 mount point can be determined by looking at the mount entry in
1089 /proc/self/mountinfo. Look at optional fields and see if any propaga‐
1090 tion properties are specified. shared:X means the mount is shared,
1091 master:X means the mount is slave and if nothing is there that means
1092 the mount is private. [1] ⟨#Footnote1⟩
1093
1094
1095 To change propagation properties of a mount point use the mount com‐
1096 mand. For example, to bind mount the source directory /foo do mount
1097 --bind /foo /foo and mount --make-private --make-shared /foo. This will
1098 convert /foo into a shared mount point. The propagation properties of
1099 the source mount can be changed directly. For instance if / is the
1100 source mount for /foo, then use mount --make-shared / to convert / into
1101 a shared mount.
1102
1103
1105 Build an image using local Containerfiles
1106 $ podman build .
1107
1108 $ podman build -f Containerfile.simple .
1109
1110 $ cat $HOME/Containerfile | podman build -f - .
1111
1112 $ podman build -f Containerfile.simple -f Containerfile.notsosimple .
1113
1114 $ podman build -f Containerfile.in $HOME
1115
1116 $ podman build -t imageName .
1117
1118 $ podman build --tls-verify=true -t imageName -f Containerfile.simple .
1119
1120 $ podman build --tls-verify=false -t imageName .
1121
1122 $ podman build --runtime-flag log-format=json .
1123
1124 $ podman build --runtime-flag debug .
1125
1126 $ podman build --authfile /tmp/auths/myauths.json --cert-dir $HOME/auth --tls-verify=true --creds=username:password -t imageName -f Containerfile.simple .
1127
1128 $ podman build --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=1024:1028 -t imageName .
1129
1130 $ podman build --security-opt label=level:s0:c100,c200 --cgroup-parent /path/to/cgroup/parent -t imageName .
1131
1132 $ podman build --volume /home/test:/myvol:ro,Z -t imageName .
1133
1134 $ podman build -v /var/lib/yum:/var/lib/yum:O -t imageName .
1135
1136 $ podman build --layers -t imageName .
1137
1138 $ podman build --no-cache -t imageName .
1139
1140 $ podman build --layers --force-rm -t imageName .
1141
1142 $ podman build --no-cache --rm=false -t imageName .
1143
1144 $ podman build --network mynet .
1145
1146
1147
1148 Building a multi-architecture image using the --manifest option (requires
1149 emulation software)
1150 $ podman build --arch arm --manifest myimage /tmp/mysrc
1151
1152 $ podman build --arch amd64 --manifest myimage /tmp/mysrc
1153
1154 $ podman build --arch s390x --manifest myimage /tmp/mysrc
1155
1156 $ podman build --platform linux/s390x,linux/ppc64le,linux/amd64 --manifest myimage /tmp/mysrc
1157
1158 $ podman build --platform linux/arm64 --platform linux/amd64 --manifest myimage /tmp/mysrc
1159
1160
1161
1162 Building an image using a URL, Git repo, or archive
1163 The build context directory can be specified as a URL to a Container‐
1164 file, a Git repository, or URL to an archive. If the URL is a Contain‐
1165 erfile, it is downloaded to a temporary location and used as the con‐
1166 text. When a Git repository is set as the URL, the repository is cloned
1167 locally to a temporary location and then used as the context. Lastly,
1168 if the URL is an archive, it is downloaded to a temporary location and
1169 extracted before being used as the context.
1170
1171
1172 Building an image using a URL to a Containerfile
1173 Podman will download the Containerfile to a temporary location and then
1174 use it as the build context.
1175
1176
1177 $ podman build https://10.10.10.1/podman/Containerfile
1178
1179
1180
1181 Building an image using a Git repository
1182 Podman will clone the specified GitHub repository to a temporary loca‐
1183 tion and use it as the context. The Containerfile at the root of the
1184 repository will be used and it only works if the GitHub repository is a
1185 dedicated repository.
1186
1187
1188 $ podman build git://github.com/scollier/purpletest
1189
1190
1191
1192 Building an image using a URL to an archive
1193 Podman will fetch the archive file, decompress it, and use its contents
1194 as the build context. The Containerfile at the root of the archive and
1195 the rest of the archive will get used as the context of the build. If
1196 you pass -f PATH/Containerfile option as well, the system will look for
1197 that file inside the contents of the archive.
1198
1199
1200 $ podman build -f dev/Containerfile https://10.10.10.1/podman/context.tar.gz
1201
1202
1203
1204 Note: supported compression formats are 'xz', 'bzip2', 'gzip' and
1205 'identity' (no compression).
1206
1207
1209 .containerignore/.dockerignore
1210 If the file .containerignore or .dockerignore exists in the context di‐
1211 rectory, podman build reads its contents. Use the --ignorefile option
1212 to override the Podman uses the content to exclude files and directo‐
1213 ries from the context directory, when executing COPY and ADD directives
1214 in the Containerfile/Dockerfile
1215
1216
1217 The .containerignore and .dockerignore files use the same syntax; if
1218 both are in the context directory, podman build will only use .con‐
1219 tainerignore.
1220
1221
1222 Users can specify a series of Unix shell globs in a .containerignore
1223 file to identify files/directories to exclude.
1224
1225
1226 Podman supports a special wildcard string ** which matches any number
1227 of directories (including zero). For example, */.go will exclude all
1228 files that end with .go that are found in all directories.
1229
1230
1231 Example .containerignore file:
1232
1233
1234 # exclude this content for image
1235 */*.c
1236 **/output*
1237 src
1238
1239
1240
1241 */*.c Excludes files and directories whose names ends with .c in any
1242 top level subdirectory. For example, the source file include/root‐
1243 less.c.
1244
1245
1246 **/output* Excludes files and directories starting with output from any
1247 directory.
1248
1249
1250 src Excludes files named src and the directory src as well as any con‐
1251 tent in it.
1252
1253
1254 Lines starting with ! (exclamation mark) can be used to make exceptions
1255 to exclusions. The following is an example .containerignore file that
1256 uses this mechanism:
1257
1258
1259 *.doc
1260 !Help.doc
1261
1262
1263
1264 Exclude all doc files except Help.doc from the image.
1265
1266
1267 This functionality is compatible with the handling of .containerignore
1268 files described here:
1269
1270
1271 https://github.com/containers/common/blob/main/docs/containerig‐
1272 nore.5.md
1273
1274
1275 registries.conf (/etc/containers/registries.conf)
1276
1277
1278 registries.conf is the configuration file which specifies which con‐
1279 tainer registries should be consulted when completing image names which
1280 do not include a registry or domain portion.
1281
1282
1284 lastlog sparse file
1285 If you are using a useradd command within a Containerfile with a large
1286 UID/GID, it will create a large sparse file /var/log/lastlog. This can
1287 cause the build to hang forever. Go language does not support sparse
1288 files correctly, which can lead to some huge files being created in
1289 your container image.
1290
1291
1292 If you are using useradd within your build script, you should pass the
1293 --no-log-init or -l option to the useradd command. This option tells
1294 useradd to stop creating the lastlog file.
1295
1296
1298 podman(1), buildah(1), containers-certs.d(5), containers-reg‐
1299 istries.conf(5), crun(1), runc(8), useradd(8), podman-ps(1), podman-
1300 rm(1), Containerfile(5), containerignore(5)
1301
1302
1304 Aug 2020, Additional options and .containerignore added by Dan Walsh
1305 <dwalsh@redhat.com>
1306
1307
1308 May 2018, Minor revisions added by Joe Doss <joe@solidadmin.com>
1309
1310
1311 December 2017, Originally compiled by Tom Sweeney <tsweeney@redhat.com>
1312
1313
1315 1: The Podman project is committed to inclusivity, a core value of open
1316 source. The master and slave mount propagation terminology used here is
1317 problematic and divisive, and should be changed. However, these terms
1318 are currently used within the Linux kernel and must be used as-is at
1319 this time. When the kernel maintainers rectify this usage, Podman will
1320 follow suit immediately.
1321
1322
1323
1324 podman-build(1)()