Convox Community

When are environment variables available?

I have a setup where my Dockerfile will call a bash script bin/createfile


FROM mysql:5.6
COPY bin/ /bin/
RUN bin/createfile
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]

Where bin/createfile will do something like this:

echo "[mysqldump]" > /etc/my.cnf
echo "user=${DbUser}" >> /etc/my.cnf
echo "password=${DbPass}" >> /etc/my.cnf
echo "" >> /etc/my.cnf
echo "[mysql]" >> /etc/my.cnf
echo "user=${DbUser}" >> /etc/my.cnf
echo "password=${DbPass}" >> /etc/my.cnf

chmod 600 /etc/my.cnf

This is so that I can run something like mysqldump without the -u -p arguments. However at this point apparently the ENV variables are not available since it will not setup the /etc/my.cnf file correctly, it will blank where the user and passwords should be filled.

I need to do this before the docker container is created, because if I run it after, I need to restart the mysql server for the changes to take effect, but doing that will shutdown the docker container.

So my question is, is this possible with this setup of having the user and password filled with my ENV variables that are stored in my Convox env secrets? Or are they only available after the docker container is up and running which pretty much makes this use case imposible.

Any suggestions are welcome.

BTW this is the setup for a Timer for automatic backups