Skip to content

Instantly share code, notes, and snippets.

@docwhat
Last active August 14, 2018 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docwhat/8f6e6b828987717797cfafc3ce33028e to your computer and use it in GitHub Desktop.
Save docwhat/8f6e6b828987717797cfafc3ce33028e to your computer and use it in GitHub Desktop.
docker-envfile-example

The format of the env-file is explain at https://docs.docker.com/compose/env-file/.

# I'm using bash, but it applies with sh and zsh as well.
$ echo $BASH_VERSION
4.4.23(1)-release
# Create a simple env-file for testing.  We're using = and ! to
# push at some corner cases.
$ echo 'THISISAVARIABLE=This is the value that even has an = sign!' > /tmp/concoction.env
$ cat /tmp/concoction.env
THISISAVARIABLE=This is the value that even has an = sign!
# Show that it is set in the environment.
$ docker run --rm --env-file=/tmp/concoction.env ubuntu env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=c3a4e92f820e
THISISAVARIABLE=This is the value that even has an = sign!
HOME=/root
# This example is quoted twice.
# The first layer is the current shell, bash.
# The second layer is used by sh
$ docker run --rm --env-file=/tmp/concoction.env ubuntu sh -c 'echo "${THISISAVARIABLE}"'
This is the value that even has an = sign!
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment