NAME
podman-build - Build a container image using a ContainerfileSYNOPSIS
podman build [options] [context]DESCRIPTION
podman build Builds an image using instructions from one or more Containerfiles or Dockerfiles and a specified build context directory. A Containerfile uses the same syntax as a Dockerfile internally. For this document, a file referred to as a Containerfile can be a file named either 'Containerfile' or 'Dockerfile'.OPTIONS
--add-host=host:ip
Add a custom host-to-IP mapping (host:ip)--all-platforms
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.--annotation=annotation
Add an image annotation (e.g. annotation=value) to the image metadata. Can be used multiple times.--arch=arch
Set the architecture of the image to be built, and that of the base image to be pulled, if the build uses one, to the provided value instead of using the architecture of the build host. Unless overridden, subsequent lookups of the same image in the local storage will match this architecture, regardless of the host. (Examples: arm, arm64, 386, amd64, ppc64le, s390x)--authfile=path
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json, which is set using podman login. If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using docker login.--build-arg=arg=value
Specifies a build argument and its value, which will be interpolated in instructions read from the Containerfiles in the same way that environment variables are, but which will not be added to environment variable list in the resulting image's configuration.--build-context=name=value
Specify an additional build context using its short name and its location. Additional build contexts can be referenced in the same manner as we access different stages in COPY instruction.- •
- 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)
- •
- HTTP URL to a tarball – e.g. --build-context src=https://example.org/releases/src.tar
- •
- Container image – specified with a container-image:// prefix, e.g. --build-context alpine=container-image://alpine:3.15, (also accepts docker://, docker-image://)
FROM [name] COPY --from=[name] ... RUN --mount=from=[name] …
- •
- Named build context defined with --build-context [name]=..
- •
- Stage defined with AS [name] inside Containerfile
- •
- Image [name], either local or in a remote registry
--cache-from
Repository to utilize as a potential cache source. When specified, Buildah will try to look for cache images in the specified repository and will attempt to pull cache images instead of actually executing the build steps locally. Buildah will only attempt to pull previously cached images if they are considered as valid cache hits.# populate a cache and also consult it buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .
--cache-to
Set this flag to specify a remote repository that will be used to store cache images. Buildah will attempt to push newly built cache image to the remote repository.# populate a cache and also consult it buildah build -t test --layers --cache-to registry/myrepo/cache --cache-from registry/myrepo/cache .
--cache-ttl
Limit the use of cached images to only consider images with created timestamps less than duration ago. For example if --cache-ttl=1h is specified, Buildah will only consider intermediate cache images which are created under the duration of one hour, and intermediate cache images outside this duration will be ignored.--cap-add=CAP_xxx
When executing RUN instructions, run the command specified in the instruction with the specified capability added to its capability set. Certain capabilities are granted by default; this option can be used to add more.--cap-drop=CAP_xxx
When executing RUN instructions, run the command specified in the instruction with the specified capability removed from its capability set. The CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_FOWNER, CAP_FSETID, CAP_KILL, CAP_NET_BIND_SERVICE, CAP_SETFCAP, CAP_SETGID, CAP_SETPCAP, CAP_SETUID, and CAP_SYS_CHROOT capabilities are granted by default; this option can be used to remove them.--cert-dir=path
Use certificates at path (*.crt, *.cert, *.key) to connect to the registry. (Default: /etc/containers/certs.d) 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)--cgroup-parent=path
Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist.--cgroupns=how
Sets the configuration for cgroup namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "private" to indicate that a new cgroup namespace should be created, or it can be "host" to indicate that the cgroup namespace in which buildah itself is being run should be reused.--compress
This option is added to be aligned with other containers CLIs. Podman doesn't communicate with a daemon or a remote server. 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)--cpp-flag=flags
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").--cpu-period=limit
Set the CPU period for the Completely Fair Scheduler (CFS), which is a duration in microseconds. Once the container's CPU quota is used up, it will not be scheduled to run until the current period ends. Defaults to 100000 microseconds.--cpu-quota=limit
Limit the CPU Completely Fair Scheduler (CFS) quota.--cpu-shares, -c=shares
CPU shares (relative weight).PID | container | CPU | CPU share |
100 | C0 | 0 | 100% of CPU0 |
101 | C1 | 1 | 100% of CPU1 |
102 | C1 | 2 | 100% of CPU2 |
--cpuset-cpus=number
CPUs in which to allow execution. Can be specified as a comma-separated list (e.g. 0,1), as a range (e.g. 0-3), or any combination thereof (e.g. 0-3,7,11-15).--cpuset-mems=nodes
Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.--creds=[username[:password]]
The [username[:password]] to use to authenticate with the registry, if required. If one or both values are not supplied, a command line prompt will appear and the value can be entered. The password is entered without echo.--decryption-key=key[:passphrase]
The [key[:passphrase]] to be used for decryption of images. Key can point to keys and/or certificates. Decryption will be tried with all keys. If the key is protected by a passphrase, it is required to be passed in the argument and omitted otherwise.--device=host-device[:container-device][:permissions]
Add a host device to the container. Optional permissions parameter can be used to specify device permissions by combining r for read, w for write, and m for mknod(2).--disable-compression, -D
Don't compress filesystem layers when building the image unless it is required by the location where the image is being written. This is the default setting, because image layers are compressed automatically when they are pushed to registries, and images being written to local storage would only need to be decompressed again to be stored. Compression can be forced in all cases by specifying --disable-compression=false.--disable-content-trust
This is a Docker-specific option to disable image verification to a container registry and is not supported by Podman. This option is a NOOP and provided solely for scripting compatibility.--dns=ipaddr
Set custom DNS servers.--dns-option=option
Set custom DNS options to be used during the build.--dns-search=domain
Set custom DNS search domains to be used during the build.--env=env[=value]
Add a value (e.g. env= value) to the built image. Can be used multiple times. If neither = nor a *value* are specified, but env is set in the current environment, the value from the current environment will be added to the image. To remove an environment variable from the built image, use the --unsetenv option.--file, -f=Containerfile
Specifies a Containerfile which contains instructions for building the image, either a local file or an http or https URL. If more than one Containerfile is specified, FROM instructions will only be accepted from the first specified file.--force-rm
Always remove intermediate containers after a build, even if the build fails (default true).--format
Control the format for the built image's manifest and configuration data. Recognized formats include oci (OCI image-spec v1.0, the default) and docker (version 2, using schema format 2 for the manifest).--from
Overrides the first FROM instruction within the Containerfile. If there are multiple FROM instructions in a Containerfile, only the first is changed.--help, -h
Print usage statement--hooks-dir=path
Each *.json file in the path configures a hook for buildah build containers. For more details on the syntax of the JSON files and the semantics of hook injection. Buildah currently support both the 1.0.0 and 0.1.0 hook schemas, although the 0.1.0 schema is deprecated.--http-proxy
Pass through HTTP Proxy environment variables.--identity-label
Adds default identity label io.buildah.version if set. (default true).--ignorefile
Path to an alternative .containerignore file.--iidfile=ImageIDfile
Write the built image's ID to the file. When --platform is specified more than once, attempting to use this option will trigger an error.--ipc=how
Sets the configuration for IPC namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "container" to indicate that a new IPC namespace should be created, or it can be "host" to indicate that the IPC namespace in which podman itself is being run should be reused, or it can be the path to an IPC namespace which is already in use by another process.--isolation=type
Controls what type of isolation is used for running processes as part of RUN instructions. Recognized types include oci (OCI-compatible runtime, the default), rootless (OCI-compatible runtime invoked using a modified configuration and its --rootless option enabled, with --no-new-keyring --no-pivot added to its create invocation, with network and UTS namespaces disabled, and IPC, PID, and user namespaces enabled; the default for unprivileged users), and chroot (an internal wrapper that leans more toward chroot(1) than container technology).--jobs=number
Run up to N concurrent stages in parallel. If the number of jobs is greater than 1, stdin will be read from /dev/null. If 0 is specified, then there is no limit in the number of jobs that run in parallel.--label=label
Add an image label (e.g. label=value) to the image metadata. Can be used multiple times.--layers
Cache intermediate images during the build process (Default is true).--logfile=filename
Log output which would be sent to standard output and standard error to the specified file instead of to standard output and standard error. This option is not supported on the remote client, including Mac and Windows (excluding WSL2) machines.--logsplit=bool-value
If --logfile and --platform are specified, the --logsplit option allows end-users to split the log file for each platform into different files in the following format: ${logfile}_${platform-os}_${platform-arch}. This option is not supported on the remote client, including Mac and Windows (excluding WSL2) machines.--manifest=manifest
Name of the manifest list to which the image will be added. Creates the manifest list if it does not exist. This option is useful for building multi architecture images.--memory, -m=number[unit]
Memory limit. A unit can be b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes).--memory-swap=number[unit]
A limit value equal to memory plus swap. A unit can be b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes).-m (--memory) By default, it is set to double the value of --memory.
--network=mode, --net
Sets the configuration for network namespaces when handling RUN instructions.- •
- none: no networking.
- •
- host: use the Podman host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
- •
- ns:path: path to a network namespace to join.
- •
- private: create a new namespace for the container (default)
- •
- <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.
--no-cache
Do not use existing cached images for the container build. Build from the start with a new set of cached layers.--no-hosts
Do not create /etc/hosts for the container. By default, Podman will manage /etc/hosts, adding the container's own IP address and any hosts from --add-host. --no-hosts disables this, and the image's /etc/hosts will be preserved unmodified.--omit-history
Omit build history information in the built image. (default false).--os=string
Set the OS of the image to be built, and that of the base image to be pulled, if the build uses one, instead of using the current operating system of the build host. Unless overridden, subsequent lookups of the same image in the local storage will match this OS, regardless of the host.--os-feature=feature
Set the name of a required operating system feature for the image which will be built. By default, if the image is not based on scratch, the base image's required OS feature list is kept, if the base image specified any. This option is typically only meaningful when the image's OS is Windows.--os-version=version
Set the exact required operating system version for the image which will be built. By default, if the image is not based on scratch, the base image's required OS version is kept, if the base image specified one. This option is typically only meaningful when the image's OS is Windows, and is typically set in Windows base images, so using this option is usually unnecessary.--output, -o=output-opts
Output destination (format: type=local,dest=path)--pid=pid
Sets the configuration for PID namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "container" to indicate that a new PID namespace should be created, or it can be "host" to indicate that the PID namespace in which podman itself is being run should be reused, or it can be the path to a PID namespace which is already in use by another process.--platform=os/arch[/variant][,...]
Set the os/arch of the built image (and its base image, if your build uses one) to the provided value instead of using the current operating system and architecture of the host (for example linux/arm). Unless overridden, subsequent lookups of the same image in the local storage will match this platform, regardless of the host.--pull=policy
Pull image policy. The default is always.- •
- always, true: Always pull the image and throw an error if the pull fails.
- •
- missing: Pull the image only if it could not be found in the local containers storage. Throw an error if no image could be found and the pull fails.
- •
- never, false: Never pull the image but use the one from the local containers storage. Throw an error if no image could be found.
- •
- newer: Pull if the image on the registry is newer than the one in the local containers storage. An image is considered to be newer when the digests are different. Comparing the time stamps is prone to errors. Pull errors are suppressed if a local image was found.
--quiet, -q
Suppress output messages which indicate which instruction is being processed, and of progress when pulling images from a registry, and when writing the output image.--retry=attempts
Number of times to retry in case of failure when performing pull of images from registry. Default is 3.--retry-delay=duration
Duration of delay between retry attempts in case of failure when performing pull of images from registry. Default is 2s.--rm
Remove intermediate containers after a successful build (default true).--runtime=path
The path to an alternate OCI-compatible runtime, which will be used to run commands specified by the RUN instruction.--runtime-flag=flag
Adds global flags for the container rutime. To list the supported flags, please consult the manpages of the selected container runtime.--secret=id=id,src=path
Pass secret information to be used in the Containerfile for building images in a safe way that will not end up stored in the final image, or be seen in other stages. The secret will be mounted in the container at the default location of /run/secrets/id.--security-opt=option
Security Options- •
- apparmor=unconfined : Turn off apparmor confinement for the container
- •
- apparmor=your-profile : Set the apparmor confinement profile for the container
- •
- label=user:USER : Set the label user for the container processes
- •
- label=role:ROLE : Set the label role for the container processes
- •
- label=type:TYPE : Set the label process type for the container processes
- •
- label=level:LEVEL : Set the label level for the container processes
- •
- label=filetype:TYPE : Set the label file type for the container files
- •
- label=disable : Turn off label separation for the container
- •
- no-new-privileges : Not supported
- •
- seccomp=unconfined : Turn off seccomp confinement for the container
- •
- seccomp=profile.json : White listed syscalls seccomp Json file to be used as a seccomp filter
--shm-size=number[unit]
Size of /dev/shm. A unit can be b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes). If the unit is omitted, the system uses bytes. If the size is omitted, the default is 64m. When size is 0, there is no limit on the amount of memory used for IPC by the container. This option conflicts with --ipc=host.--sign-by=fingerprint
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,)--skip-unused-stages
Skip stages in multi-stage builds which don't affect the target stage. (Default: true).--squash
Squash all of the image's new layers into a single new layer; any preexisting layers are not squashed.--squash-all
Squash all of the new image's layers (including those inherited from a base image) into a single new layer.--ssh=default | id[=socket>
SSH agent socket or keys to expose to the build. The socket path can be left empty to use the value of default=$SSH_AUTH_SOCK--stdin
Pass stdin into the RUN containers. Sometime commands being RUN within a Containerfile want to request information from the user. For example apt asking for a confirmation for install. Use --stdin to be able to interact from the terminal during the build.--tag, -t=imageName
Specifies the name which will be assigned to the resulting image if the build process completes successfully. If imageName does not include a registry name, the registry name localhost will be prepended to the image name.--target=stageName
Set the target build stage to build. When building a Containerfile with multiple build stages, --target can be used to specify an intermediate build stage by name as the final stage for the resulting image. Commands after the target stage will be skipped.--timestamp=seconds
Set the create timestamp to seconds since epoch to allow for deterministic builds (defaults to current time). By default, the created timestamp is changed and written into the image manifest with every commit, causing the image's sha256 hash to be different even if the sources are exactly the same otherwise. When --timestamp is set, the created timestamp is always set to the time specified and therefore not changed, allowing the image's sha256 hash to remain the same. All files committed to the layers of the image will be created with the timestamp.--tls-verify
Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true, TLS verification will be used. If set to false, TLS verification will not be used. If not specified, TLS verification will be used unless the target registry is listed as an insecure registry in containers-registries.conf(5)--ulimit=type=soft-limit[:hard-limit]
Specifies resource limits to apply to processes launched when processing RUN instructions. This option can be specified multiple times. Recognized resource types include:"core": maximum core dump size (ulimit -c)
"cpu": maximum CPU time (ulimit -t)
"data": maximum size of a process's data segment (ulimit -d)
"fsize": maximum size of new files (ulimit -f)
"locks": maximum number of file locks (ulimit -x)
"memlock": maximum amount of locked memory (ulimit -l)
"msgqueue": maximum amount of data in message queues (ulimit -q)
"nice": niceness adjustment (nice -n, ulimit -e)
"nofile": maximum number of open files (ulimit -n)
"nproc": maximum number of processes (ulimit -u)
"rss": maximum size of a process's (ulimit -m)
"rtprio": maximum real-time scheduling priority (ulimit -r)
"rttime": maximum amount of real-time execution between blocking syscalls
"sigpending": maximum number of pending signals (ulimit -i)
"stack": maximum stack size (ulimit -s)
--unsetenv=env
Unset environment variables from the final image.--userns=how
Sets the configuration for user namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "container" to indicate that a new user namespace should be created, it can be "host" to indicate that the user namespace in which podman itself is being run should be reused, or it can be the path to a user namespace which is already in use by another process.--userns-gid-map=mapping
Directly specifies a GID mapping which should be used to set ownership, at the filesystem level, on the working container's contents. Commands run when handling RUN instructions will default to being run in their own user namespaces, configured using the UID and GID maps.--userns-gid-map-group=group
Specifies that a GID mapping which should be used to set ownership, at the filesystem level, on the working container's contents, can be found in entries in the /etc/subgid file which correspond to the specified group. Commands run when handling RUN instructions will default to being run in their own user namespaces, configured using the UID and GID maps. If --userns-uid-map-user is specified, but --userns-gid-map-group is not specified, podman will assume that the specified user name is also a suitable group name to use as the default setting for this option.--userns-uid-map=mapping
Directly specifies a UID mapping which should be used to set ownership, at the filesystem level, on the working container's contents. Commands run when handling RUN instructions will default to being run in their own user namespaces, configured using the UID and GID maps.--userns-uid-map-user=user
Specifies that a UID mapping which should be used to set ownership, at the filesystem level, on the working container's contents, can be found in entries in the /etc/subuid file which correspond to the specified user. Commands run when handling RUN instructions will default to being run in their own user namespaces, configured using the UID and GID maps. If --userns-gid-map-group is specified, but --userns-uid-map-user is not specified, podman will assume that the specified group name is also a suitable user name to use as the default setting for this option.--uts=how
Sets the configuration for UTS namespaces when handling RUN instructions. The configured value can be "" (the empty string) or "container" to indicate that a new UTS namespace should be created, or it can be "host" to indicate that the UTS namespace in which podman itself is being run should be reused, or it can be the path to a UTS namespace which is already in use by another process.--variant=variant
Set the architecture variant of the image to be built, and that of the base image to be pulled, if the build uses one, to the provided value instead of using the architecture variant of the build host.--volume, -v=[HOST-DIR:CONTAINER-DIR[:OPTIONS]]
Create a bind mount. If you specify -v /HOST-DIR:/CONTAINER-DIR, Podman bind mounts /HOST-DIR in the host to /CONTAINER-DIR in the Podman container. (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines)- •
- [rw|ro]
- •
- [z|Z|O]
- •
- [U]
- •
- [[r]shared|[r]slave|[r]private]
$ podman build --security-opt label=disable -v $HOME:/home/user .
- Overlay mounts are not currently supported in rootless mode. - The `O` flag is not allowed to be specified with the `Z` or `z` flags.
On SELinux systems, labels in the source directory needs to be readable by the container label. If not, SELinux container separation must be disabled for the container to work.
- Modification of the directory volume mounted into the container with an overlay mount can cause unexpected failures. It is recommended that you do not modify the directory until the container finishes running.
EXAMPLES
Build an image using local Containerfiles
$ podman build . $ podman build -f Containerfile.simple . $ cat $HOME/Containerfile | podman build -f - . $ podman build -f Containerfile.simple -f Containerfile.notsosimple . $ podman build -f Containerfile.in $HOME $ podman build -t imageName . $ podman build --tls-verify=true -t imageName -f Containerfile.simple . $ podman build --tls-verify=false -t imageName . $ podman build --runtime-flag log-format=json . $ podman build --runtime-flag debug . $ podman build --authfile /tmp/auths/myauths.json --cert-dir $HOME/auth --tls-verify=true --creds=username:password -t imageName -f Containerfile.simple . $ podman build --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=1024:1028 -t imageName . $ podman build --security-opt label=level:s0:c100,c200 --cgroup-parent /path/to/cgroup/parent -t imageName . $ podman build --volume /home/test:/myvol:ro,Z -t imageName . $ podman build -v /var/lib/yum:/var/lib/yum:O -t imageName . $ podman build --layers -t imageName . $ podman build --no-cache -t imageName . $ podman build --layers --force-rm -t imageName . $ podman build --no-cache --rm=false -t imageName . $ podman build --network mynet .
Building a multi-architecture image using the --manifest option (requires emulation software)
$ podman build --arch arm --manifest myimage /tmp/mysrc $ podman build --arch amd64 --manifest myimage /tmp/mysrc $ podman build --arch s390x --manifest myimage /tmp/mysrc $ podman build --platform linux/s390x,linux/ppc64le,linux/amd64 --manifest myimage /tmp/mysrc $ podman build --platform linux/arm64 --platform linux/amd64 --manifest myimage /tmp/mysrc
Building an image using a URL, Git repo, or archive
The build context directory can be specified as a URL to a Containerfile, a Git repository, or URL to an archive. If the URL is a Containerfile, it is downloaded to a temporary location and used as the context. When a Git repository is set as the URL, the repository is cloned locally to a temporary location and then used as the context. Lastly, if the URL is an archive, it is downloaded to a temporary location and extracted before being used as the context.Building an image using a URL to a Containerfile
Podman will download the Containerfile to a temporary location and then use it as the build context.$ podman build https://10.10.10.1/podman/Containerfile
Building an image using a Git repository
Podman will clone the specified GitHub repository to a temporary location and use it as the context. The Containerfile at the root of the repository will be used and it only works if the GitHub repository is a dedicated repository.$ podman build https://github.com/scollier/purpletest
Building an image using a URL to an archive
Podman will fetch the archive file, decompress it, and use its contents as the build context. The Containerfile at the root of the archive and the rest of the archive will get used as the context of the build. If you pass -f PATH/Containerfile option as well, the system will look for that file inside the contents of the archive.$ podman build -f dev/Containerfile https://10.10.10.1/podman/context.tar.gz
Files
.containerignore/.dockerignore
If the file .containerignore or .dockerignore exists in the context directory, podman build reads its contents. Use the --ignorefile option to override the Podman uses the content to exclude files and directories from the context directory, when executing COPY and ADD directives in the Containerfile/Dockerfile# exclude this content for image */*.c **/output* src
*.doc !Help.doc