liveBook · Manning

Env directive

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

The ENV directive defines default environment variables in a container image.

The ENV directive adds default environment variables to a container image. Podman makes these variables available during image builds and when containers run from the image. section 2.3.1

Setting a default variable

ENV foo="bar" defines foo with the value bar for subsequent image-building steps and for containers launched from the resulting image. section 2.3.1

Table 2.7 Containerfile directives that define the OCI Runtime Specification (view table figure)

Directive examples

Explanation

CMD /usr/bin/start.sh

Specifies the default command to run when launching a container off this image. If CMD is not specified, the parent image’s CMD is inherited. Note that RUN and CMD are very different. RUN runs the commands during the build process, while CMD is only used when a user launches the image without specifying a command.

ENTRYPOINT “/bin/sh -c”

Allows you to configure a container to run as an executable. The ENTRYPOINT instruction is not overwritten when arguments are passed to podman run. This allows arguments to be passed to the entrypoint—for instance, podman run <image> -d passes the -d argument to the ENTRYPOINT.

ENV foo=”bar”

Adds an environment variable to be used during both the image build and container execution.

EXPOSE 8080

Announces the port that containerized applications will be exposing. This does not actually map or open any ports.

LABEL Description=”Web browser which displays Hello World”

Adds metadata to an image.

MAINTAINER Daniel Walsh

Sets the Author field for the generated images.

STOPSIGNAL SIGTERM

Sets the default stop signal sent to the container to exit. The signal can be a valid unsigned number or a signal name in the format SIGNAME.

USER apache

Sets the user name (or UID) and group name (or GID) to use for any RUN, CMD, and ENTRYPOINT specified after it.

ONBUILD

Adds a trigger instruction to the image to be executed at a later time, when the image is used as the base for another build.

WORKDIR /var/www/html

Sets the working directory for RUN, CMD, ENTRYPOINT, and COPY directives. A directory will be created if it doesn’t exist.

Use the OCI Runtime Specification directive table to compare ENV with CMD, ENTRYPOINT, and EXPOSE, which describe how Podman runs the image. section 2.3.1

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

How deep it goes
Defines the directive and its two application phases, but does not detail variable precedence or interpolation.
Examples
Uses ENV foo="bar" to demonstrate declaring a default environment variable.
What it assumes
Assumes familiarity with Containerfiles, image builds, and Podman container launches.
What you can do after
Operate/configure images by declaring environment defaults available during builds and container launches.
How it connects
Connects Containerfile syntax with CMD, ENTRYPOINT, EXPOSE, and the OCI Runtime Specification.

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.