# When are environment variables available?

**URL:** <https://community.convox.com/t/when-are-environment-variables-available/627>\
**Category:** Configuration\
**Created:** [October 8, 2019, 10:41pm UTC](https://community.convox.com/t/when-are-environment-variables-available/627 "2019-10-08T22:41:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moises](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/moises/32/97_2.png) [@moises](https://community.convox.com/u/moises)\
**Post date:** [October 8, 2019, 10:41pm UTC](https://community.convox.com/t/when-are-environment-variables-available/627/1 "2019-10-08T22:41:40Z")

</div>

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

Dockerfile:

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

```

Where `bin/createfile` will do something like this:

```auto
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](https://docs.convox.com/application/timers) for automatic backups

---

<div class="post-metadata">

**Author:** ![syngency](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/syngency/32/150_2.png) [@syngency](https://community.convox.com/u/syngency)\
**Post date:** [June 18, 2020, 1:25am UTC](https://community.convox.com/t/when-are-environment-variables-available/627/2 "2020-06-18T01:25:12Z")

</div>

Did you ever find a solution for this? We’re needing to do something similar – pass AWS credentials to a grunt task in our Dockerfile.

---

<div class="post-metadata">

**Author:** ![moises](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.convox.com/moises/32/97_2.png) [@moises](https://community.convox.com/u/moises)\
**Post date:** [June 18, 2020, 3:44am UTC](https://community.convox.com/t/when-are-environment-variables-available/627/3 "2020-06-18T03:44:47Z")

</div>

@syngency for this specific use case I did not find a solution.
