简体   繁体   中英

Azure Web Service env-variables not working with Azure Container Registry (ACR) image

I'm relatively new to Azure and Docker and I'm encountering some problems.

We are building a web app at work using Laravel 8 and Docker. We have local Ubuntu VM in which we pull the latest git commit and then build the Docker image using the docker build command. We then tag and push our image to our remote Azure Container Registry which lives in the same Resource Group as our Azure Web Service.

Now the thing is: when I try to let's say add my database credentials in the configuration section of the Azure portal, these variables are not read when the Azure Web Service implements the website using the latest ACR image.Variables like port and websites_port will work but not my DB credentials and other stuff like my MAIL SMTP creds.

However, when I try to put these variables in a dedicated.env file inside my Ubuntu VM and then build the image with the.env file included then the credentials are being recognized. But this is bad behaviour because we don't want our.env file to be included in the ACR image. It's like adding a.env file to your git repo. It shouldn't be there in the image.

How does this work?

So I managed to fix it myself.

What I did was add the php artisan optimize command as a start-up command to my start-container Bash script which is included in Laravel by default when you're using Laravel Sail.

The cause of my portal variables not being recognized had to do with the fact that my app was still pointing to the old.env variables that were in my image. Clearing and then re-caching the config variables did the trick. Now everytime Azure starts the container it will run the artisan command to re-configure the portal 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