LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

What is the difference between ARG and ENV in a Dockerfile?

ARG is a build-time variable that only exists while the image is built; ENV sets an environment variable that is stored in the image and visible to the application in every container.

ARG ENV
Lifetime Only during docker build Baked into the image; present in every container
Set from outside docker build --build-arg CODE_VERSION=3.20 . docker run -e APACHE_RUN_USER=nobody … overrides it
Typical use Choosing a base image version, a download URL Configuring the app: APACHE_RUN_USER, APACHE_LOG_DIR

ARG is the only instruction allowed before FROM, which makes it useful to parameterise the base image itself:

ARG CODE_VERSION=latest
FROM alpine:${CODE_VERSION}

The ENV values from the lab's exercise image can be checked inside the running container with echo $APACHE_RUN_USER, which prints www-data.

Gotcha: neither is a safe place for secrets. ENV values are visible to anyone who can run docker image inspect, and ARG values used in a RUN step show up in docker image history.

Go deeper:

From Quiz: ISLAB / Docker Introduction | Updated: Dec 01, 2026