简体   繁体   English

Azure 应用服务环境变量在容器中不可用

[英]Azure App Service environment variables are not available in container

I have a Docker container running in Azure App Service.我有一个 Docker 容器在 Azure 应用服务中运行。 In my Azure App Service on Configuration section I have a list of defined variables for database connection.在我的 Azure App Service on Configuration 部分中,我有一个用于数据库连接的已定义变量列表。 I want to use them in my docker container in wp-config.php file to connect to Azure MySQL database.我想在 wp-config.php 文件中的 docker 容器中使用它们来连接到 Azure Z632AZ504B9591DCCA76 数据库。 However, the variables are not available in container at all.但是,这些变量在容器中根本不可用。

I have tried reviewing them with 'env' or 'printenv' commands after adding the following line in my start script:在我的启动脚本中添加以下行后,我尝试使用“env”或“printenv”命令查看它们:

eval $(printenv | sed -n "s/^\([^=]\+\)=\(.*\)$/export \1=\2/p" | sed 's/"/\\\"/g' | sed '/=/s//="/' | sed 's/$/"/' >> /etc/profile)

No success, unfortunately.没有成功,很遗憾。 I have also tried getting them via PHP with getenv('variable_name') function, also no success.我也试过通过 PHP 和 getenv('variable_name') function 来获取它们,也没有成功。 All of my environment variables are available in the Kudu container which is created alongside the actual container running my app within App Service, however, I cannot use them at all in my application container.我的所有环境变量都在 Kudu 容器中可用,该容器与在应用服务中运行我的应用程序的实际容器一起创建,但是,我根本无法在我的应用程序容器中使用它们。 The container itself is Apache + WordPress image and I am attaching my Dockerfile and startup script below:容器本身是 Apache + WordPress 图像,我附上了我的 Dockerfile 和下面的启动脚本:

Dockerfile: Dockerfile:

FROM wordpress:4.9.1-apache
RUN apt-get update
RUN apt-get -y install openssh-server \
    && echo "root:Docker!" | chpasswd

COPY sshd_config /etc/ssh/
RUN mkdir -p /tmp
COPY ssh_setup.sh /tmp
RUN chmod +x /tmp/ssh_setup.sh \
    && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)

COPY . /var/www/html

RUN chown -R www-data:www-data /var/www/html/

ENV PORT 80
EXPOSE 80 2222

ADD start.sh /
RUN chmod +x /start.sh
ENTRYPOINT ["/start.sh"]

Start.sh:开始.sh:

#!/bin/bash
/usr/sbin/sshd
apache2-foreground
eval $(printenv | sed -n "s/^\([^=]\+\)=\(.*\)$/export \1=\2/p" | sed 's/"/\\\"/g' | sed '/=/s//="/' | sed 's/$/"/' >> /etc/profile)

UPD: The issue was due to the app setting that enabled persistent storage. UPD:问题是由于启用持久存储的应用程序设置造成的。 Once I changed value from 'true' to 'false', for some reason, application settings started to work as environment variables.一旦我将值从“真”更改为“假”,出于某种原因,应用程序设置开始作为环境变量工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Azure 应用服务上的 NodeJS 容器上设置环境变量 - Unable to set the environment variables on a NodeJS Container on Azure App Service Azure 应用服务将变量环境外部化到我的 Angular web 应用程序中 - Azure app service externalize variables environment into my Angular web application Azure:如何在不重启应用服务的情况下重新加载环境变量 - Azure: How to reload the Environment Variables without rebooting the App Service Azure App Service - 解析docker-compose yml中的环境变量 - Azure App Service - resolving environment variables in docker-compose yml 以编程方式设置 Azure 应用服务应用程序设置/环境变量 - Programmatically set Azure App Service application settings / environment variables Azure 带有“WEBSITE_”前缀的应用服务环境变量? - Azure App Service environment variables with “WEBSITE_” prefix? 如何列出 Azure 应用服务只读环境变量 - How to list Azure app service read-only environment variables Azure Web 自定义容器中的应用程序,环境变量未从应用程序服务传播到容器 - Azure Web App in custom container, env variables not propagated from app service to container Azure 容器实例 | 来自环境变量文件的环境变量 - Azure Container Instance | Environment Variables from an Environment Variables File 使用自定义容器环境变量部署 Azure Webapp - Deploy Azure Webapp with custom container environment variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM