简体   繁体   中英

Variable substitutions in docker-compose in Azure Docker Web app

I have a docker-compose file that contains a secret for my database.

port: 4466
managementApiSecret: ${DB_SECRET}

So I would like to use Docker-Compose's Variable Substitution ( https://docs.docker.com/compose/compose-file/#variable-substitution ) to be able to provide my secrets through an environment variable instead of my yaml file.

Is this at all possible using the "Application Settings" variables on my Azure Linux Docker Instance?

It doesn't seem to work for me, I've tried both ${VAR} and $VAR syntax and neither worked. I also tried with secrets that only contain alphanumerics and numbers.

Thanks in advance. Frank

Environment variables that you need to start the container (for example: you want to include build number in container name) can be added to .env file in same directory as the docker-compose.yml file.

sample .env file:

DB_SECRET=foo

run: docker-compose config and verify that the variable has been substituted with the value you have in .env file

Also, I recommend using managementApiSecret:"${DB_SECRET}" (note the quotes around the variable) in your docker-compose.yml file

There might be azure specific way to share secrets but I didn't try that yet.

If you want to pass in environment variables that the container needs, then https://docs.docker.com/compose/compose-file/#env_file is what you want. Those environment vars will become part of environment inside docker container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM