Azure App Service - 在 docker-compose yml 中解析环境变量
Azure App Service - resolving environment variables in docker-compose yml
我有一个多容器应用程序,我想在 Azure 应用服务中部署和 运行。我的撰写文件 docker-compose.prod.yml 包含环境变量(如下面的代码所示)。
当我 运行 在本地构建 compose 文件时,这些变量在构建过程中通过引用位于同一目录中的环境文件 (env.) 来解析:
docker-compose -f docker-compose.prod.yml build
push
我知道可以构建 DevOps 管道(如 here 所述),它将在构建过程中插入环境变量,类似于我在本地构建它的方式。
但是,我想知道是否可以
1.) 通过 Azure 门户 Web 界面配置环境变量(就像您可以对应用程序设置所做的那样),然后 docker 撰写文件可以引用这些环境变量以在启动时解析这些变量
或
2.) 以某种方式上传环境。我在本地使用的文件可用于在创建或启动时解析变量。
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
感谢任何反馈,谢谢
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
据我所知,Azure Web App 目前不支持使用变量代替真实图像。 docker-compose文件中只能使用Azure给定的一些变量,比如持久化存储的变量WEBAPP_STORAGE_HOME
。
2.) somehow upload the env. file I use locally which can then be used to resolve the variables on create or startup
而且也不支持env。文件中,所有 docker 命令都由 Azure 在后端执行。否则,Azure Web App 也不支持 docker-compopse 文件中的 build
选项,请参阅 supported options.
我一直在为完全相同的问题而苦苦挣扎。经过大量搜索后,我找到了 this post describing a nice little hack.
将此添加到您的 init/startup 脚本中:
# Get environment variables to show up in SSH session
eval $(printenv | awk -F= '{print "export " "\"""\"""=""\"""\"" }' >> /etc/profile)
我现在可以通过 SSH 运行 我的管理命令。
我有一个多容器应用程序,我想在 Azure 应用服务中部署和 运行。我的撰写文件 docker-compose.prod.yml 包含环境变量(如下面的代码所示)。
当我 运行 在本地构建 compose 文件时,这些变量在构建过程中通过引用位于同一目录中的环境文件 (env.) 来解析:
docker-compose -f docker-compose.prod.yml build
push
我知道可以构建 DevOps 管道(如 here 所述),它将在构建过程中插入环境变量,类似于我在本地构建它的方式。
但是,我想知道是否可以
1.) 通过 Azure 门户 Web 界面配置环境变量(就像您可以对应用程序设置所做的那样),然后 docker 撰写文件可以引用这些环境变量以在启动时解析这些变量
或
2.) 以某种方式上传环境。我在本地使用的文件可用于在创建或启动时解析变量。
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
感谢任何反馈,谢谢
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
据我所知,Azure Web App 目前不支持使用变量代替真实图像。 docker-compose文件中只能使用Azure给定的一些变量,比如持久化存储的变量WEBAPP_STORAGE_HOME
。
2.) somehow upload the env. file I use locally which can then be used to resolve the variables on create or startup
而且也不支持env。文件中,所有 docker 命令都由 Azure 在后端执行。否则,Azure Web App 也不支持 docker-compopse 文件中的 build
选项,请参阅 supported options.
我一直在为完全相同的问题而苦苦挣扎。经过大量搜索后,我找到了 this post describing a nice little hack.
将此添加到您的 init/startup 脚本中:
# Get environment variables to show up in SSH session
eval $(printenv | awk -F= '{print "export " "\"""\"""=""\"""\"" }' >> /etc/profile)
我现在可以通过 SSH 运行 我的管理命令。