Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Fun in the RUN instruction: Why container builds with distroless images can surprise you

May 14, 2026
Matt Micene
Related topics:
Hardened imagesContainersSecurity
Related products:
Red Hat Enterprise Linux

    I've done a fair amount of work with Containerfiles recently, working with image mode hosts. I wasn't doing anything particularly complicated in design—some multi-stage builds, some heredoc usage. Nothing really challenged my fundamental understanding of how podman build reads and executes instructions.

    Then I started building examples for the Early Access program of Red Hat Hardened Images and, in particular, using the python image from the catalog for a few personal projects. The project has been evolving quickly over the past six months, and one of those changes made me question everything I thought I knew about container builds.

    I had a simple Flask application based on a UBI image that I wanted to run in a Hardened Image, and the Containerfile looked a little like this one:

    FROM {hummingbird-registry}/python:3.14
    # Set the working directory in the container
    WORKDIR /app
    # Copy the application files to the target directory
    # COPY always executes as root
    COPY --chown=65532 app.py .
    COPY --chown=65532 index.html static/
    # Set environment variables for Python
    ENV PYTHONDONTWRITEBYTECODE=1 \
        PYTHONUNBUFFERED=1
    # Switch to root from the non-root user to install dependencies
    # By default, these install in /tmp/.local for the non-root user
    USER root
    RUN pip install flask
    # Switch to the default non-root user for runtime
    USER ${CONTAINER_DEFAULT_USER} 
    # Expose the port Flask will listen on
    EXPOSE 8080
    # Appropriately set the stop signal for the python interpreter executed as PID 1
    STOPSIGNAL SIGINT
    ENTRYPOINT ["python", "./app.py"]

    That's a pretty straightforward build: copy the application files as the right user, then run pip install to get the dependencies. But here's what happened when I executed the first build:

    STEP 7/11: RUN pip install flask
    error running container: from /usr/bin/crun creating container for [/bin/sh -c pip install flask]: executable file `/bin/sh` not found: No such file or directory

    Why is /bin/sh missing? And what's calling it in the first place?

    The first answer is simple. These images are distroless, which means that shells and other tools not directly used by python are removed from the final image. This reduces the footprint and the attack surface. But it also means we need to revisit how container builds actually function—or I needed to, at least.

    First, let's make sure pip is actually available. We can just run the container and check.

    podman run --rm quay.io/hummingbird/python:3.14 /usr/bin/pip install flask
    Defaulting to user installation because normal site-packages is not writeable
    Collecting flask
      Downloading flask-3.1.3-py3-none-any.whl.metadata (3.2 kB)
    Collecting blinker>=1.9.0 (from flask)
      Downloading blinker-1.9.0-py3-none-any.whl.metadata (1.6 kB)
    Collecting click>=8.1.3 (from flask)
    < truncated output >
    Successfully installed blinker-1.9.0 click-8.3.2 flask-3.1.3 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.3 werkzeug-3.1.8

    OK, so pip is available in the image. That means the issue lies with the RUN instruction itself. I mentioned heredoc support I've been using in image mode for a reason, as it should have been a clue why this pip install failed in the distroless python. The RUN instruction operates inside the context of the image and executes the command provided via a shell.

    If you haven't seen it before, the heredoc support replaces the usual " line continuation with \" practice. The outcome is about the same, but the way we get there changes. In practice it looks like this:

    RUN<<EOF
    dnf -y install curl httpd
    dnf clean all 
    rm -rf /var/cache/dnf/*
    EOF

    This is clearly the same format and style used by shells like bash and zsh. It should have also been a big hint that not having a shell available might affect how RUN works.

    We all use this shell support regularly, probably without really thinking about the implications. Usually, doing any of the following actions will just work:

    • Continuing a command on multiple lines for readability
    • Expanding an image-defined environment variable (ENV) in a command
    • Using a heredoc to combine multiple complex commands in a single layer

    These all work because the RUN command uses the shell inside the container to execute whatever is written as a command line. That was the source of the error in this build: it tried to /bin/sh -c pip install flask—but alas, /bin/sh is nowhere to be found.

    What I had forgotten was that the RUN command also supports the exec format. What's that, you ask?

    Well, we all use that format regularly too, in the CMD or ENTRYPOINT instructions. For years, the common wisdom for CMD instructions has been to use the bracketed argument list format. This is how we run as PID 1, trap signals, and more. We probably don't even think much about how we structure RUN, CMD, or ENTRYPOINT commands anymore.

    So you too might have forgotten that the RUN instruction can also use the same exec format to run directly instead of as a child process in a shell. In practice, that means my working pip install line looks more like a CMD instruction:

    RUN ["/usr/bin/pip", "install", "flask" ]

    In a distroless image, it's still possible to directly call the binaries in the container. Not having a shell doesn't necessarily mean you need to jump to a builder variant to use tools already installed. You just might need to adapt some of the expectations of how those tools are called.

    Resources

    • To learn more, visit the Red Hat Hardened Images product page.
    • To discover your next favorite image, head to red.ht/hi and find the tools and runtimes to support your workload.

    Related Posts

    • Build trusted Python containers with Project Hummingbird and Calunga

    • Exploring distroless containers with Project Hummingbird

    • Reproducible builds in Project Hummingbird

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    What’s up next?

    Container Coloring Book e-book tile card

    The Container Coloring Book: Who's afraid of the big bad wolf?

    Dan Walsh
    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.