In this post, we're going to talk about how to use
buildah to build container images on CentOS.
buildah is a command line tool that facilitates building OCI compliant images. There's a plethora of information available around what
buildah is on its GitHub landing page so we won't dive more into what it is. However, it's worth mentioning that
buildah helps you build container images without having to run any daemon in the background, unlike the
docker CLI tool which requires the Docker daemon to be running in the background.
buildah is already available in the CentOS repos. All we need to do is:
$ yum install -y buildah $ buildah -v buildah version 1.5-dev (image-spec 1.0.0, runtime-spec 1.0.0)
buildah offers a number of features and options. To know about these, simply execute
buildah on the command line or refer to its manual page (
Building the container image
buildah can build a container image by referring the same Dockerfile that
docker build refers to. Let's consider this simple Dockerfile for example. All it does is install the
$ cat Dockerfile FROM registry.centos.org/centos/centos RUN yum install -y wget && yum clean all
Now, build the container image named
$ buildah bud -t wget . $ buildah images IMAGE ID IMAGE NAME CREATED AT SIZE 2f254a4fff8d registry.centos.org/centos/centos:latest Dec 17, 2018 05:07 210 MB 9b6563cfaff2 localhost/wget:latest Jan 16, 2019 11:01 234 MB
You can use this container image with
podman by doing:
$ podman run -it --rm wget bash
podman is a tool for managing pods, containers, and container images. Its website contains extensive detail about its capabilities and uses.
Use the container image with Docker
buildah also makes it possible to use the image thus built via the local Docker daemon. It's as simple as doing a
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE $ buildah images IMAGE ID IMAGE NAME CREATED AT SIZE 2f254a4fff8d registry.centos.org/centos/centos:latest Dec 17, 2018 05:07 210 MB 9b6563cfaff2 localhost/wget:latest Jan 16, 2019 11:01 234 MB $ buildah push wget:latest docker-daemon:registry.centos.org/centos/wget:latest Getting image source signatures Copying blob sha256:b05580fca2f9aabb2d8fa975b29146c9147c8418e559f197c54a4fac04babb95 200.47 MiB / 200.47 MiB [==================================================] 4s Copying blob sha256:fa5e7b9f8f4d8f07f7af27cd06269ba16ba0f06cbacacc7c7e96a616da885cab 22.82 MiB / 22.82 MiB [====================================================] 0s Copying config sha256:9b6563cfaff28baa1075e86b60c502f85fc31b56bdb641d314a7c61d2e91fae8 1.33 KiB / 1.33 KiB [======================================================] 0s Writing manifest to image destination Storing signatures Successfully pushed registry.centos.org/centos/wget:latest@sha256:66f4c1c8378c7d9e22a0d3c9a0943739082dfeae3344e5f2b069e9c9ddf08271 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.centos.org/centos/wget latest 9b6563cfaff2 6 minutes ago 226 MB
Initially, the local Docker daemon storage had no container images. We did
buildah push wget:latest docker-daemon:registry.centos.org/wget:latest to push the image to local Docker daemon's storage. Now doing
docker images shows the image and can then be used with
In this blog, we saw simple steps that need to be performed to install and use
buildah to build OCI images which can then be pushed to local Docker daemon's storage.
buildah can also push container images to the remote registry. It is highly recommended to read the documentation to know about more features and capabilities of
In a future blog, we will share how the CentOS Container Pipeline team managed to build container images on OpenShift using