[英]Azure App Service - resolving environment variables in docker-compose yml
I have a multicontainer application that I would like to deploy and run within an Azure App Service.我有一个多容器应用程序,我想在 Azure 应用服务中部署和运行。 The compose file I have, docker-compose.prod.yml, contains environment variables (as shown in the below code).
我的撰写文件 docker-compose.prod.yml 包含环境变量(如下面的代码所示)。
When I run build the compose file locally, these variables are resolved during the build process by referencing an environment file (env.) located in the same directory:当我在本地运行构建撰写文件时,这些变量在构建过程中通过引用位于同一目录中的环境文件 (env.) 来解析:
docker-compose -f docker-compose.prod.yml build
push
docker-compose -f docker-compose.prod.yml build
push
I know that it is possible to build a DevOps pipeline (as described here ), which will insert environment variables during the build process, similar to how I build it locally.我知道可以构建 DevOps 管道(如此处所述),它将在构建过程中插入环境变量,类似于我在本地构建它的方式。
However, I wanted to know if it is possible to either但是,我想知道是否有可能
1.) configure environment variables via the Azure Portal web interface (as you can do with application settings), which the docker compose file can then reference to resolve these variables on startup 1.) 通过 Azure Portal web 界面配置环境变量(就像您可以在应用程序设置中做的那样),然后 docker 撰写文件可以在启动时引用这些变量来解析这些变量
or要么
2.) somehow upload the env. 2.) 以某种方式上传环境。 file I use locally which can then be used to resolve the variables on create or startup.
我在本地使用的文件,然后可用于在创建或启动时解析变量。
Contents of docker-compose.prod.yml
--------------------------------------------
version: '3.7'
services:
app1:
build: ./app1
command : python3 manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
image: "${AZ_CONTAINER_REGISTRY}/${APP1_IMAGE}:${APP1_VERSION}"
app2:
build: ./app2
command: python app.py
ports:
- 8081:8080
image: "${AZ_CONTAINER_REGISTRY}/${APP2_IMAGE}:${APP2_VERSION}"
restart: always
Contents of env. file
--------------------------------------------
AZ_CONTAINER_REGISTRY=sample.azurecr.io
APP1_IMAGE=app1test
APP1_VERSION=1.0
APP2_IMAGE=app2test
APP2_VERSION=2.0
Any feedback is appreciated, thanks感谢任何反馈,谢谢
1.) configure environment variables via the Azure Portal web interface (as you can do with application settings), which the docker compose file can then reference to resolve these variables on startup
1.) 通过 Azure Portal web 界面配置环境变量(就像您可以在应用程序设置中做的那样),然后 docker 撰写文件可以在启动时引用这些变量来解析这些变量
According to my knowledge, the Azure Web App does not support that uses variables instead of the real image currently.据我所知,Azure Web App目前不支持使用变量代替真实图像。 Only some variables that Azure gives can be used in the docker-compose file, such as the variable
WEBAPP_STORAGE_HOME
for persistent storage. docker-compose文件中只能使用Azure给出的一些变量,比如持久化存储的变量
WEBAPP_STORAGE_HOME
。
2.) somehow upload the env.
2.) 以某种方式上传环境。 file I use locally which can then be used to resolve the variables on create or startup
我在本地使用的文件可用于在创建或启动时解析变量
And it also does not support the env.而且它也不支持环境。 file, all the docker commands are executed by Azure in the backend.
文件中,所有的docker命令都是由Azure在后台执行的。 Otherwise, the Azure Web App also does not support the
build
option in the docker-compopse file, see the supported options .否则Azure Web App也不支持docker-compopse文件中的
build
选项,查看supported options 。
I was struggling with the exact same question.我正在为完全相同的问题而苦苦挣扎。 After a lot of searching I found this post describing a nice little hack .
经过大量搜索后,我发现这篇文章描述了一个不错的小技巧。
Add this to your init/startup script:将此添加到您的初始化/启动脚本中:
# Get environment variables to show up in SSH session
eval $(printenv | awk -F= '{print "export " "\""$1"\"""=""\""$2"\"" }' >> /etc/profile)
I can now run my management commands via SSH.我现在可以通过 SSH 运行我的管理命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.