Docker Running containers Setting environment variables

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

$ docker run -e "ENV_VAR=foo" ubuntu /bin/bash

Both -e and --env can be used to define environment variables inside of a container. It is possible to supply many environment variables using a text file:

$ docker run --env-file ./env.list ubuntu /bin/bash

Example environment variable file:

# This is a comment
TEST_HOST=10.10.0.127

The --env-file flag takes a filename as an argument and expects each line to be in the VARIABLE=VALUE format, mimicking the argument passed to --env. Comment lines need only be prefixed with #.

Regardless of the order of these three flags, the --env-file are processed first, and then -e/--env flags. This way, any environment variables supplied individually with -e or --env will override variables supplied in the --env-var text file.



Got any Docker Question?