简体   繁体   中英

Azure App Service environment variables are not available in container

I have a Docker container running in Azure App Service. In my Azure App Service on Configuration section I have a list of defined variables for database connection. I want to use them in my docker container in wp-config.php file to connect to Azure MySQL database. 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:

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. 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. The container itself is Apache + WordPress image and I am attaching my Dockerfile and startup script below:

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:

#!/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. Once I changed value from 'true' to 'false', for some reason, application settings started to work as environment variables.

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