buildah-bud - Build an image using instructions from Dockerfiles.
buildah build-using-dockerfile [options] context
buildah bud [options] context
bud is an alias for build-using-dockerfile.
Builds an image using instructions from one or more Dockerfiles and a specified build context directory.
The build context directory can be specified as the http(s) URL of an archive, git repository or Dockerfile.
Dockerfiles ending with a ".in" suffix will be preprocessed via CPP(1). This can be useful to decompose Dockerfiles into several reusable parts that can be used via CPP's #include directive. Notice, a Dockerfile.in file can still be used by other tools when manually preprocessing them via cpp -E
.
When the URL is an archive, the contents of the URL is downloaded to a temporary location and extracted before execution.
When the URL is an Dockerfile, the Dockerfile is downloaded to a temporary location.
When a Git repository is set as the URL, the repository is cloned locally and then set as the context.
--add-host=[]
Add a custom host-to-IP mapping (host:ip)
Add a line to /etc/hosts. The format is hostname:ip. The --add-host option can be set multiple times.
--annotation annotation
Add an image annotation (e.g. annotation=value) to the image metadata. Can be used multiple times.
Note: this information is not present in Docker image formats, so it is discarded when writing images in Docker formats.
--authfile path
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json, which is set using buildah 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 Dockerfiles in the same way that environment variables are, but which will not be added to environment variable list in the resulting image's configuration.
--cache-from
Images to utilise as potential cache sources. Buildah does not currently support caching so this is a NOOP.
--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_AUDIT_WRITE, CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_FOWNER, CAP_FSETID, CAP_KILL, CAP_MKNOD, 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.
If a capability is specified to both the --cap-add and --cap-drop options, it will be dropped, regardless of the order in which the options were given.
--cert-dir path
Use certificates at path (*.crt, *.cert, *.key) to connect to the registry. Default certificates directory is /etc/containers/certs.d.
--cgroup-parent=""
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.
--compress
This option is added to be aligned with other containers CLIs. Buildah doesn't send a copy of the context directory to a daemon or a remote server. Thus, compressing the data before sending it is irrelevant to Buildah.
--cni-config-dir=directory
Location of CNI configuration files which will dictate which plugins will be
used to configure network interfaces and routing for containers created for
handling RUN
instructions, if those containers will be run in their own
network namespaces, and networking is not disabled.
--cni-plugin-path=directory[:directory[:directory[...]]]
List of directories in which the CNI plugins which will be used for configuring network namespaces can be found.
--cpu-period=0
Limit the CPU CFS (Completely Fair Scheduler) period
Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify.
--cpu-quota=0
Limit the CPU CFS (Completely Fair Scheduler) quota
Limit the container's CPU usage. By default, containers run with the full CPU resource. This flag tell the kernel to restrict the container's CPU usage to the quota you specify.
--cpu-shares, -c=0
CPU shares (relative weight)
By default, all containers get the same proportion of CPU cycles. This proportion can be modified by changing the container's CPU share weighting relative to the weighting of all other running containers.
To modify the proportion from the default of 1024, use the --cpu-shares flag to set the weighting to 2 or higher.
The proportion will only apply when CPU-intensive processes are running. When tasks in one container are idle, other containers can use the left-over CPU time. The actual amount of CPU time will vary depending on the number of containers running on the system.
For example, consider three containers, one has a cpu-share of 1024 and two others have a cpu-share setting of 512. When processes in all three containers attempt to use 100% of CPU, the first container would receive 50% of the total CPU time. If you add a fourth container with a cpu-share of 1024, the first container only gets 33% of the CPU. The remaining containers receive 16.5%, 16.5% and 33% of the CPU.
On a multi-core system, the shares of CPU time are distributed over all CPU cores. Even if a container is limited to less than 100% of CPU time, it can use 100% of each individual CPU core.
For example, consider a system with more than three cores. If you start one container {C0} with -c=512 running one process, and another container {C1} with -c=1024 running two processes, this can result in the following division of CPU shares:
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=""
CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems=""
Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
If you have four memory nodes on your system (0-3), use --cpuset-mems=0,1
then processes in your container will only use memory from the first
two memory nodes.
--creds creds
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.
--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 Docker registry and is not supported by Buildah. This flag is a NOOP and provided soley for scripting compatibility.
--dns=[]
Set custom DNS servers
This option can be used to override the DNS configuration passed to the container. Typically this is necessary when the host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this is the case the --dns
flag is necessary for every run.
The special value none can be specified to disable creation of /etc/resolv.conf in the container by Buildah. The /etc/resolv.conf file in the image will be used without changes.
--dns-option=[]
Set custom DNS options
--dns-search=[]
Set custom DNS search domains
--file, -f Dockerfile
Specifies a Dockerfile which contains instructions for building the image, either a local file or an http or https URL. If more than one Dockerfile is specified, FROM instructions will only be accepted from the first specified file.
If a local file is specified as the Dockerfile and it does not exist, the context directory will be prepended to the local file value.
If you specify -f -
, the Dockerfile contents will be read from stdin.
--force-rm bool-value
Always remove intermediate containers after a build, even if the build fails (default false).
--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).
Note: You can also override the default format by setting the BUILDAH_FORMAT
environment variable. export BUILDAH_FORMAT=docker
--http-proxy
By default proxy environment variables are passed into the container if set
for the buildah process. This can be disabled by setting the --http-proxy
option to false
. The environment variables passed in include http_proxy
,
https_proxy
, ftp_proxy
, no_proxy
, and also the upper case versions of
those.
Defaults to true
--iidfile ImageIDfile
Write the image ID to the file.
--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 buildah
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, with --no-new-keyring 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).
Note: You can also override the default isolation type by setting the
BUILDAH_ISOLATION environment variable. export BUILDAH_ISOLATION=oci
--label label
Add an image label (e.g. label=value) to the image metadata. Can be used multiple times.
--loglevel number
Adjust the logging level up or down. Valid option values range from -2 to 3, with 3 being roughly equivalent to using the global --debug option, and values below 0 omitting even error messages which accompany fatal errors.
--layers bool-value
Cache intermediate images during the build process (Default is false
).
Note: You can also override the default value of layers by setting the BUILDAH_LAYERS
environment variable. export BUILDAH_LAYERS=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.
--memory, -m=""
Memory limit (format: [], where unit = b, k, m or g)
Allows you to constrain the memory available to a container. If the host supports swap memory, then the -m memory setting can be larger than physical RAM. If a limit of 0 is specified (not using -m), the container's memory is not limited. The actual limit may be rounded up to a multiple of the operating system's page size (the value would be very large, that's millions of trillions).
--memory-swap="LIMIT"
A limit value equal to memory plus swap. Must be used with the -m
(--memory) flag. The swap LIMIT
should always be larger than -m
(--memory) value. By default, the swap LIMIT
will be set to double
the value of --memory.
The format of LIMIT
is <number>[<unit>]
. Unit can be b
(bytes),
k
(kilobytes), m
(megabytes), or g
(gigabytes). If you don't specify a
unit, b
is used. Set LIMIT to -1
to enable unlimited swap.
--net how --network how
Sets the configuration for network namespaces when handling RUN
instructions.
The configured value can be "" (the empty string) or "container" to indicate
that a new network namespace should be created, or it can be "host" to indicate
that the network namespace in which buildah
itself is being run should be
reused, or it can be the path to a network namespace which is already in use by
another process.
--no-cache
Do not use existing cached images for the container build. Build from the start with a new set of cached layers.
--pid how
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 buildah
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="Linux"
This option has no effect on the build. Other container engines use this option to control the execution platform for the build (e.g., Windows, Linux) which is not required for Buildah as it supports only Linux.
--pull
When the flag is enabled, attempt to pull the latest image from the registries listed in registries.conf if a local image does not exist or the image is newer than the one in storage. Raise an error if the image is not in any listed registry and is not present locally.
If the flag is disabled (with --pull=false), do not pull the image from the registry, use only the local version. Raise an error if the image is not present locally.
Defaults to true.
--pull-always
Pull the image from the first registry it is found in as listed in registries.conf. Raise an error if not found in the registries, even if the image is present locally.
--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.
--rm bool-value
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. Default is runc.
Note: You can also override the default runtime by setting the BUILDAH_RUNTIME
environment variable. export BUILDAH_RUNTIME=/usr/local/bin/runc
--runtime-flag flag
Adds global flags for the container rutime. To list the supported flags, please
consult the manpages of the selected container runtime (runc
is the default
runtime, the manpage to consult is runc(8)
).
Note: Do not pass the leading --
to the flag. To pass the runc flag --log-format json
to buildah bud, the option given would be --runtime-flag log-format=json
.
--security-opt=[]
Security Options
"label=user:USER" : Set the label user for the container "label=role:ROLE" : Set the label role for the container "label=type:TYPE" : Set the label type for the container "label=level:LEVEL" : Set the label level for the container "label=disable" : Turn off label confinement 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
"apparmor=unconfined" : Turn off apparmor confinement for the container "apparmor=your-profile" : Set the apparmor confinement profile for the container
--shm-size=""
Size of /dev/shm
. The format is <number><unit>
. number
must be greater than 0
.
Unit is optional and can be b
(bytes), k
(kilobytes), m
(megabytes), or g
(gigabytes).
If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses 64m
.
--squash
Squash all of the new image's layers (including those inherited from a base image) into a single new layer.
--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 Dockerfile 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.
--tls-verify bool-value
Require HTTPS and verify certificates when talking to container registries (defaults to true).
--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": maximimum 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)
"nofile": maximum number of open files (1048576); when run by root
"nproc": maximum number of processes (ulimit -u)
"nproc": maximum number of processes (1048576); when run by root
"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)
--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 buildah
itself is being run should be reused, or
it can be the path to an user namespace which is already in use by another
process.
--userns-uid-map mapping
Directly specifies a UID mapping which should be used to set ownership, at the
filesytem 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.
Entries in this map take the form of one or more triples of a starting in-container UID, a corresponding starting host-level UID, and the number of consecutive IDs which the map entry represents.
This option overrides the remap-uids setting in the options section of /etc/containers/storage.conf.
If this option is not specified, but a global --userns-uid-map setting is supplied, settings from the global option will be used.
If none of --userns-uid-map-user, --userns-gid-map-group, or --userns-uid-map are specified, but --userns-gid-map is specified, the UID map will be set to use the same numeric values as the GID map.
--userns-gid-map mapping
Directly specifies a GID mapping which should be used to set ownership, at the
filesytem 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.
Entries in this map take the form of one or more triples of a starting in-container GID, a corresponding starting host-level GID, and the number of consecutive IDs which the map entry represents.
This option overrides the remap-gids setting in the options section of /etc/containers/storage.conf.
If this option is not specified, but a global --userns-gid-map setting is supplied, settings from the global option will be used.
If none of --userns-uid-map-user, --userns-gid-map-group, or --userns-gid-map are specified, but --userns-uid-map is specified, the GID map will be set to use the same numeric values as the UID map.
--userns-uid-map-user user
Specifies that a UID mapping which should be used to set ownership, at the
filesytem 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, buildah
will assume that the specified group name is also a
suitable user name to use as the default setting for this option.
--userns-gid-map-group group
Specifies that a GID mapping which should be used to set ownership, at the
filesytem 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, buildah
will assume that the specified user name is also a
suitable group name to use as the default setting for this option.
--uts how
Sets the configuration for UTS namespaces when the 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 buildah
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.
--volume, -v[=[HOST-DIR:CONTAINER-DIR[:OPTIONS]]]
Create a bind mount. If you specify, -v /HOST-DIR:/CONTAINER-DIR
, Buildah
bind mounts /HOST-DIR
in the host to /CONTAINER-DIR
in the Buildah
container. The OPTIONS
are a comma delimited list and can be:
- [rw|ro]
- [z|Z|O]
- [
[r]shared
|[r]slave
|[r]private
]
The CONTAINER-DIR
must be an absolute path such as /src/docs
. The HOST-DIR
must be an absolute path as well. Buildah bind-mounts the HOST-DIR
to the
path you specify. For example, if you supply /foo
as the host path,
Buildah copies the contents of /foo
to the container filesystem on the host
and bind mounts that into the container.
You can specify multiple -v options to mount one or more mounts to a container.
You can add the :ro
or :rw
suffix to a volume to mount it read-only or
read-write mode, respectively. By default, the volumes are mounted read-write.
See examples.
Labeling Volume Mounts
Labeling systems like SELinux require that proper labels are placed on volume content mounted into a container. Without a label, the security system might prevent the processes running inside the container from using the content. By default, Buildah does not change the labels set by the OS.
To change a label in the container context, you can add either of two suffixes
:z
or :Z
to the volume mount. These suffixes tell Buildah to relabel file
objects on the shared volumes. The z
option tells Buildah that two containers
share the volume content. As a result, Buildah labels the content with a shared
content label. Shared volume labels allow all containers to read/write content.
The Z
option tells Buildah to label the content with a private unshared label.
Only the current container can use a private volume.
Overlay Volume Mounts
The :O
flag tells Buildah to mount the directory from the host as a temporary storage using the Overlay file system. The RUN
command containers are allowed to modify contents within the mountpoint and are stored in the container storage in a separate directory. In Ovelay FS terms the source directory will be the lower, and the container storage directory will be the upper. Modifications to the mount point are destroyed when the RUN
command finishes executing, similar to a tmpfs mount point.
Any subsequent execution of RUN
commands sees the original source directory content, any changes from previous RUN commands no longer exists.
One use case of the overlay
mount is sharing the package cache from the host into the container to allow speeding up builds.
Note:
- Overlay mounts are not currently supported in rootless mode.
- The `O` flag is not allowed to be specified with the `Z` or `z` flags. Content mounted into the container is labeled with the private label.
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.
By default bind mounted volumes are private
. That means any mounts done
inside container will not be visible on the host and vice versa. This behavior can
be changed by specifying a volume mount propagation property.
When the mount propagation policy is set to shared
, any mounts completed inside
the container on that volume will be visible to both the host and container. When
the mount propagation policy is set to slave
, one way mount propagation is enabled
and any mounts completed on the host for that volume will be visible only inside of the container.
To control the mount propagation property of the volume use the :[r]shared
,
:[r]slave
or :[r]private
propagation flag. The propagation property can
be specified only for bind mounted volumes and not for internal volumes or
named volumes. For mount propagation to work on the source mount point (the mount point
where source dir is mounted on) it has to have the right propagation properties. For
shared volumes, the source mount point has to be shared. And for slave volumes,
the source mount has to be either shared or slave.
Use df <source-dir>
to determine the source mount and then use
findmnt -o TARGET,PROPAGATION <source-mount-dir>
to determine propagation
properties of source mount, if findmnt
utility is not available, the source mount point
can be determined by looking at the mount entry in /proc/self/mountinfo
. Look
at optional fields
and see if any propagaion properties are specified.
shared:X
means the mount is shared
, master:X
means the mount is slave
and if
nothing is there that means the mount is private
.
To change propagation properties of a mount point use the mount
command. For
example, to bind mount the source directory /foo
do
mount --bind /foo /foo
and mount --make-private --make-shared /foo
. This
will convert /foo into a shared
mount point. The propagation properties of the source
mount can be changed directly. For instance if /
is the source mount for
/foo
, then use mount --make-shared /
to convert /
into a shared
mount.
buildah bud .
buildah bud -f Dockerfile.simple .
cat ~/Dockerfile | buildah bud -f - .
buildah bud -f Dockerfile.simple -f Dockerfile.notsosimple .
buildah bud -t imageName .
buildah bud --tls-verify=true -t imageName -f Dockerfile.simple .
buildah bud --tls-verify=false -t imageName .
buildah bud --runtime-flag log-format=json .
buildah bud --runtime-flag debug .
buildah bud --authfile /tmp/auths/myauths.json --cert-dir ~/auth --tls-verify=true --creds=username:password -t imageName -f Dockerfile.simple .
buildah bud --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=1024:1028 -t imageName .
buildah bud --security-opt label=level:s0:c100,c200 --cgroup-parent /path/to/cgroup/parent -t imageName .
buildah bud --volume /home/test:/myvol:ro,Z -t imageName .
buildah bud -v /var/lib/dnf:/var/lib/dnf:O -t imageName .
buildah bud --layers -t imageName .
buildah bud --no-cache -t imageName .
buildah bud --layers --force-rm -t imageName .
buildah bud --no-cache --rm=false -t imageName .
buildah bud --dns-search=example.com --dns=223.5.5.5 --dns-option=use-vc .
This will clone the specified GitHub repository from the URL and use it as context. The Dockerfile at the root of the repository is used as Dockerfile. This only works if the GitHub repository is a dedicated repository.
buildah bud github.com/scollier/purpletest
Note: You can set an arbitrary Git repository via the git:// scheme.
Buildah will fetch the tarball archive, decompress it and use its contents as the build context. The Dockerfile at the root of the archive and the rest of the archive will get used as the context of the build. If you pass an -f PATH/Dockerfile option as well, the system will look for that file inside the contents of the tarball.
buildah bud -f dev/Dockerfile https://10.10.10.1/docker/context.tar.gz
Note: supported compression formats are 'xz', 'bzip2', 'gzip' and 'identity' (no compression).
registries.conf (/etc/containers/registries.conf
)
registries.conf is the configuration file which specifies which container registries should be consulted when completing image names which do not include a registry or domain portion.
policy.json (/etc/containers/policy.json
)
Signature policy file. This defines the trust policy for container images. Controls which container registries can be used for image, and whether or not the tool should trust the images.
buildah(1), CPP(1), buildah-login(1), docker-login(1), namespaces(7), pid_namespaces(7), policy.json(5), registries.conf(5), user_namespaces(7)