Passing Travis environment variables to Docker

im working with MongoDB, I have password saved in my travis env. I want to pass this password in my docker run command in my script. Is this possible? This is what I have now:

docker run -e password=$PASSWORD img_name

$PASSWORD is the env variable saved in travis. this command doesn’t work, fist of fall is it possible to pass a travis env variable in a bash script? and if so, how do we properly do it?

Hey @SolarUltima,

Remember in Travis, single quotes will prevent variable expansion.

In your .travis.yml, call your bash script via:


In your script try adding the following near the top (near the shebang line, I’d recommend):

docker run -e password=$1 img_name

The $1 argument will be passed to the bash script and in turn, specifically in this case with Mongo $1 is the value of $PASSWORD which is stored in this case AS the env var in Travis, so it can be called correctly and accessed as a secret.

Happy building!
Montana Mendy
Travis CI Staff

1 Like