liveBook · Manning

From instruction

As explained in Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more

The FROM directive specifies the base image or empty starting filesystem for a container image build.

The FROM instruction defines the starting point for a container image. Every Containerfile requires it, and it normally names an existing image to use as the base. section 2.3.1

Choose the starting filesystem according to the build:

  • Use FROM scratch to allocate an empty rootfs, then populate it with COPY and other build instructions. section 2.3.1
  • Use an existing image, such as registry.access.redhat.com/ubi8, to pull a base image into container storage. section 2.3.1
  • Treat the selected image as the base layer; subsequent instructions operate on its mounted rootfs and add content. section 2.3.1
  • Place FROM first; use it multiple times when creating multiple build stages. section 2.3.1

Build an HTTP application image

Create a Containerfile containing FROM ubi8/httpd-24 followed by COPY index.html /var/www/html/index.html, then run podman build -t quay.io/rhatdan/myimage ./myapp. The build pulls the base image, copies the application file, commits the result, and tags the new image. section 2.3.2

Table 2.6 Containerfile directives that update the image (view table figure)

Directive examples

Explanation

FROM quay.io/rhatdan/myimage

Sets the base image for subsequent instructions. Containerfiles must have FROM as their first instruction. The FROM may appear multiple times within a single Containerfile to create multiple build stages.

ADD start.sh /usr/bin/start.sh

Copies new files, directories, or remote file URLs to the filesystem of the container at a specified path.

COPY start.sh /usr/bin/start.sh

Copies files to the filesystem of the container at a specified path.

RUN dnf -y update

Executes commands in a new layer on top of the current image and commits the results. The committed image is used for the next step in the Containerfile.

VOLUME /var/lib/mydata

Creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or from other containers. For more on volumes, see chapter 3.

Compare FROM with other Containerfile directives that update the image or define runtime behavior. section 2.3.1

How Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more covers it

How deep it goes
Explains required placement, scratch semantics, registry pulls, rootfs mounting, base layers, and multiple build stages.
Examples
Demonstrates FROM scratch, registry.access.redhat.com/ubi8, ubi8/httpd-24, and a two-step HTTP application build.
What it assumes
Assumes familiarity with Containerfiles, container images, registries, and Podman build contexts while defining rootfs behavior.
What you can do after
Build an image from an empty rootfs or selected base image using Podman and subsequent Containerfile instructions.
How it connects
Links Containerfiles to container images, rootfs, COPY, RUN, registries, container storage, and build stages.

Also explained in

Compare how 3 books explain from instruction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more. The section links point to the parts of the book it draws on.