Build-time variable

2 snippets in Docker

DKDocker

ENV — Set Environment Variables

DK · Dockerfile
syntax
ENV <key>=<value> [<key>=<value>...]
example
ENV NODE_ENV=production
ENV APP_PORT=3000 LOG_LEVEL=info

Note ENV values persist into the running container and into child images. If you only need a variable during build time (e.g., a version number), use ARG instead to avoid leaking it into the final image.

ARG — Build-Time Variables

DK · Dockerfile
syntax
ARG <name>[=<default_value>]
example
ARG NODE_VERSION=20
FROM node:${NODE_VERSION}-alpine

ARG BUILD_DATE
LABEL build-date=$BUILD_DATE

Note ARG values are only available during build (not at runtime). Pass them with docker build --build-arg NODE_VERSION=22. ARG before FROM is only in scope for the FROM line itself — redeclare it after FROM if needed later.