Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variables with double asterisks in Dockerfile

I have noticed that in some Dockerfile the environment variables are specified using particular expressions, that perform some sort of variable substitution, such as:

ENV PASSWORD **Random**
ENV NAME **False**

I cannot find any reference to those expression in the Docker official documentation.

Where I can find a list of possible expressions that can be used in a Dockerfile and what is their meaning?

like image 736
lec00q Avatar asked Nov 10 '22 15:11

lec00q


1 Answers

It's non-official convention to use these variables as template variables. They will be replaced in run-time.

Or you can replace them using -e switch of docker run.

For example:

ENV MYSQL_USER admin
ENV MYSQL_PASS **Random**

# Replication ENV
ENV REPLICATION_MASTER **False**
ENV REPLICATION_SLAVE **False**

If you take a look on start script you can see the following:

if [ "$MYSQL_PASS" = "**Random**" ]; then
    unset MYSQL_PASS
fi

PASS=${MYSQL_PASS:-$(pwgen -s 12 1)}

If variable value is **Random** let's replace it with a randomly generated password.

like image 192
Oleg Pavliv Avatar answered Nov 15 '22 06:11

Oleg Pavliv