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