Dockerfile instructions

Dockerfile ENV

Sets environment defaults for subsequent build steps and containers. Runtime -e may override a container value; it does not change the source image. Avoid credentials. A same-named ENV overrides ARG for subsequent RUN instructions; neither is a secret channel.

Formal Syntax & Structure

docker syntaxdocker
ENV <key>=<value> ...

Parameters & Attributes

NameTypeDescription
keystringEnvironment variable name.
valuestringDefault value.

Working Example

Example Snippetdocker
FROM busybox:1.37ARG BUILD_COLOR=blueRUN printf "%s\n" "$BUILD_COLOR" > /build-color.txtENV APP_MODE=demoCMD ["sh", "-c", "cat /build-color.txt; printf \"%s\\n\" \"$APP_MODE\""]
Docker Reference