Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Getting started with Buildah

January 11, 2021
Cedric Clyburn
Related topics:
ContainersLinuxKubernetes
Related products:
Red Hat OpenShift

Share:

    If you're looking to build Open Container Initiative (OCI) container images without a full container runtime or daemon installed, Buildah is the perfect solution. Now, Buildah is an open-source, Linux-based tool that can build Docker- and Kubernetes-compatible images, and is easy to incorporate into scripts and build pipelines. In addition, Buildah has overlap functionality with Podman, Skopeo, and CRI-O.

    Buildah has the ability to create a working container from scratch, but also from a pre-existing Dockerfile. Plus, with it not needing a daemon, you'll never have to worry about Docker daemon issues when building container images.

    Let's explore some practical examples to demonstrate how simple it is to get started with Buildah, and how easily a container image can be created.

    Installing Buildah

    If you're running Red Hat Enterprise Linux 9 (RHEL 9), follow the steps below. For Fedora users, be sure to replace yum with dnf:

    $ yum -y install buildah

    For other distributions of Linux, follow these docs.

    Basic commands

    To get to know Buildah, let's play around with some basic commands. The command buildah --version will output the current version of our Buildah install, and buildah --help will help if you get stuck.

    For example, in order to pull a container image from a repository, use the from variable. For example, if your favorite Linux distribution is CentOS:

    $ buildah from centos

    After pulling the image and storing it on the host, list our current images by running buildah images. This behavior is similar to Podman and Docker, as many commands are cross-compatible. To get a list of our container images, which are ready as soon as the image pull is completed, use buildah containers.

    The output of the command "buildah containers", showing CONTAINER ID, BUILDER, IMAGE ID, IMAGE NAME, and CONTAINER #

    Figure 1: Listing our stored container images

    Finally, since we've pulled and displayed a container, let's clean up and remove our running containers with buildah rm -all. Be sure to exercise caution, however, as Buildah has the ability to remove a running container while Docker does not.

    Building a container

    Time to get hands-on with Buildah and build an Apache web server that will run inside a container. To get things started, let's pull a CentOS base image and start working:

    $ buildah from centos

    You'll see the default image name as output in the console like centos-working-container, giving us the ability to run commands within the specified container. For our case, we'll be installing an httpd package, which can be done using the following command:

    $ buildah run centos-working-container yum install httpd -y

    Once we've installed httpd, we can focus on creating a main page to be directed to on our web server, commonly known as an index.html file. To create a simple file without having to worry about formatting, use the echo command below:

    $ echo "Hello from Red Hat" > index.html

    In addition, after creating this new file, let's copy it into our current working container with the Buildah copy function. The default location for publicly accessible files is also included:

    $ buildah copy centos-working-container index.html /var/www/html/index.html

    To start this container, we must configure an entry point for a container, which is used to start httpd as the container begins and keep it in the foreground:

    $ buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" centos-working-container

    Finally, let's commit our changes to the container, and prepare it to be pushed to any container registry you'd like (ex. Docker and Quay.io):

    $ buildah commit centos-working-container redhat-website

    Your redhat-website image is ready to run with Podman, or pushed to your registry of choice.

    Building with a Dockerfile

    Another significant part of Buildah is the ability to build images using a Dockerfile, and the build-using-dockerfile, or bud command can do just that. Let's take an example Dockerfile as input, and output an OCI image:

    # CoreOS Base
    FROM fedora:latest
    # Install httpd
    RUN echo "Installing httpd"; yum -y install httpd
    # Expose the default httpd port 80
    EXPOSE 80
    # Run httpd
    CMD ["/usr/sbin/httpd", "-DFOREGROUND"]

    Once we save this file as Dockerfile in our local directory, we can use the bud command to build the image:

    $ buildah bud -t fedora-httpd

    To double-check our progress, let's run buildah images and ensure we can see our new fedora-httpd image resting in our localhost repository. Now, feel free to again run the image with Podman, or push it to your favorite registry.

    Conclusion

    Great job! We've gone through building a container from scratch, as well as from a predefined Dockerfile. Buildah is a lightweight and flexible way to create container images without the need for a runtime or daemon installed.

    You can continue to experiment with Buildah, which offers you an interactive environment right in your browser.

    If you need container orchestration, you can use Buildah with Kubernetes or Red Hat OpenShift. To get started with these platforms, see kubernetesbyexample.com and learn.openshift.com.

    Resources

    Learn more about Buildah:

    • Podman and Buildah for Docker users (William Henry)
    • Best practices for running Buildah in a container (Daniel Walsh)
    • Build and run Buildah inside a Podman container (Tom Sweeney)
    Last updated: June 7, 2023

    Recent Posts

    • Profiling vLLM Inference Server with GPU acceleration on RHEL

    • Network performance in distributed training: Maximizing GPU utilization on OpenShift

    • Clang bytecode interpreter update

    • How Red Hat has redefined continuous performance testing

    • Simplify OpenShift installation in air-gapped environments

    What’s up next?

    cheat sheet cover image

    Buildah is a lightweight and flexible command-line tool that lets you create container images without running a full Docker daemon. With our Buildah Cheat Sheet, get a head start on incorporating Buildah into your scripts and build pipelines.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue