[英]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.