Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Docker and environment variables with ENV

  • ENV
  • --env
FROM ubuntu:22.10

ENV FIRST Foo

CMD echo $FIRST $SECOND

We can declare environment variables and give them values inside the Docker file using the ENV keyword.

When running docker we can override these and provide other environment varibles using the --env command-line parameter.

docker build -t mydocker .
$ docker run --rm mydocker
Foo
$ docker run --rm --env SECOND=Bar mydocker
Foo Bar
$ docker run --rm --env SECOND=Bar --env FIRST=Peti qqrq
Peti Bar