liveBook · Manning

Copy instruction

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

The COPY directive adds files, directories, or archive contents from the build host to the image filesystem.

The COPY instruction adds files, directories, or tarballs from the local build host to a specified path in the image filesystem. It is commonly used after FROM has established the image's base root filesystem. section 2.3.1

During podman build, Podman mounts the base image through container storage and a copy-on-write filesystem. COPY then adds content to the newly created rootfs as the image is built. section 2.3.1

Use COPY to:

  • Transfer build-context files into application or configuration paths inside the image. section 2.3.2
  • Populate an image created from FROM scratch or extend an existing base image. section 2.3.1
  • Keep build-time commands separate from file transfer: RUN executes commands during construction, while COPY adds files. section 2.3.1

Copy an application page

Place index.html and a Containerfile in the myapp context directory, then write COPY index.html /var/www/html/index.html. Build it with podman build -t quay.io/rhatdan/myimage ./myapp. 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 COPY with ADD, RUN, FROM, and other directives that update an image. section 2.3.1

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

How deep it goes
Explains sources, destinations, rootfs population, and practical builds, but defers detailed path and archive semantics.
Examples
Uses index.html copied into an HTTP server document root and shows the resulting podman build output.
What it assumes
Assumes basic Containerfile structure and filesystem paths while establishing FROM, image roots, and build contexts.
What you can do after
Build it into an image by placing files in a context directory and invoking podman build.
How it connects
Connects COPY with Containerfile, Dockerfile, FROM, context directory, podman build, image layers, and container storage.

Also explained in

Compare how 2 books explain copy 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.