Overview:
- Convert a Docker Compose configuration to work with Web App for Containers
- Deploy a multi-container app to Azure
- Add application settings
- Use persistent storage for your containers
- Connect to Azure Database for MySQL
- Troubleshoot errors
Recap
Before we get started, below is just a Recap, overall steps required for Containers:
| 1 | Prepare app for AKS (Compose Docker) | Get the app/Clone; Compose Docker File (means, create the container image, download redis image etc, and start the app local using Docker compose command. docker compose -f docker-compose-quickstart.yml up -d |
| 2 | Create ACR | Create Azure Container Registry, BUILD and PUSH the image to ACR az acr build –registry $ACRNAME –image aks-store-demo/product-service:latest ./src/product-service/ |
| 3 | Create AKS | Create AKS cluster; az aks create \ –resource-group myResourceGroup \ –name myAKSCluster \ –node-count 2 \ –generate-ssh-keys \ –attach-acr <acrName> |
| 4 | Run App | Update the image names in Kubernetes manifest file and include the ACR Login server name. containers: … – name: order-service image: <acrName>.azurecr.io/aks-store-demo/order-service:latest And deploy the App by command kubectl apply -f aks-store-quickstart.yaml Test the app: kubectl get service store-front –watch |
| 5 | Scale App/Upgrade App | kubectl get pods kubectl scale –replicas=5 deployment.apps/store-front Autoscale Pods using Manifest file. spec: maxReplicas: 10 # define max replica count minReplicas: 3 # define min replica count |
Demo (Summary):
| Create Resource Group | az group create –name myResourceGroup –location “South Central US” | |
| Create App Service Plan | az appservice plan create –name myAppServicePlan1 –resource-group myResourceGroup1 –sku S1 –is-linux | |
| Create Multi container Web App | az webapp create –resource-group myResourceGroup1 –plan myAppServicePlan1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml | |
| Connect to production database | az mysql server create –resource-group myResourceGroup1 –name mysql-server-name-rk –location “South Central US” –admin-user adminuser –admin-password My5up3rStr0ngPaSw0rd! –sku-name B_Gen5_1 –version 5.7 | |
| Configure Server Firewall: | az mysql server firewall-rule create –name allAzureIPs –server mysql-server-name-rk –resource-group myResourceGroup1 –start-ip-address 0.0.0.0 –end-ip-address 0.0.0.0 | |
| Create the WordPress database | az mysql db create –resource-group myResourceGroup1 –server-name mysql-server-name-rk –name wordpress | |
| Configure database variables in WordPress | az webapp config appsettings set –resource-group myResourceGroup1 –name myappname-rk –settings WORDPRESS_DB_HOST=”mysql-server-name-rk.mysql.database.azure.com” WORDPRESS_DB_USER=”adminuser” WORDPRESS_DB_PASSWORD=”My5up3rStr0ngPaSw0rd!” WORDPRESS_DB_NAME=”wordpress” MYSQL_SSL_CA=”BaltimoreCyberTrustroot.crt.pem” | |
| Add in docker compose.yml | Use a custom image for MySQL TLS/SSL and other configurations | |
| Update app with new configuration: | az webapp config container set –resource-group myResourceGroup1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml | |
| Browse the app | ||
| Add persistent storage | az webapp config appsettings set –resource-group myResourceGroup1 –name myappname-rk –settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE | |
| Update app with new configuration/Compose | az webapp config container set –resource-group myResourceGroup1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml | |
| Browse the app | ||
Demo (Step-by-step)
| REPO: | C:\Users\metra\source\repos\Labs\AKS – ACR – DevOps\webapp and db-2 |
| Sample App: | https://github.com/Azure-Samples/multicontainerwordpress |
Old code:
version: '3.3'
services:
wordpress:
image: mcr.microsoft.com/azuredocs/multicontainerwordpress
ports:
- "8000:80"
restart: always
redis:
image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
environment:
- ALLOW_EMPTY_PASSWORD=yes
restart: always
New Code:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:create a multi-container app in Web App for Containers.
| Code1 | az group create –name myResourceGroup –location “South Central US” |
| Code2 | az appservice plan create –name myAppServicePlan1 –resource-group myResourceGroup1 –sku S1 –is-linux |
| Code3 | az webapp create –resource-group myResourceGroup1 –plan myAppServicePlan1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml |
Congratulations, you’ve created a multi-container app in Web App for Containers.
Next you’ll configure your app to use Azure Database for MySQL. Don’t install WordPress at this time.
Connect to production database
| Code1 | az mysql server create –resource-group myResourceGroup1 –name mysql-server-name-rk –location “South Central US” –admin-user adminuser –admin-password My5up3rStr0ngPaSw0rd! –sku-name B_Gen5_1 –version 5.7 |
Configure server firewall
Create a firewall rule for your MySQL server to allow client connections by using the az mysql server firewall-rule create command. When both starting IP and end IP are set to 0.0.0.0, the firewall is only opened for other Azure resources.
| Configure Server Firewall: | az mysql server firewall-rule create –name allAzureIPs –server mysql-server-name-rk –resource-group myResourceGroup1 –start-ip-address 0.0.0.0 –end-ip-address 0.0.0.0 |
Create the WordPress database
| Create the WordPress database | az mysql db create –resource-group myResourceGroup1 –server-name mysql-server-name-rk –name wordpress |
Configure database variables in WordPress
| Configure database variables in WordPress : | az webapp config appsettings set –resource-group myResourceGroup1 –name myappname-rk –settings WORDPRESS_DB_HOST=”mysql-server-name-rk.mysql.database.azure.com” WORDPRESS_DB_USER=”adminuser” WORDPRESS_DB_PASSWORD=”My5up3rStr0ngPaSw0rd!” WORDPRESS_DB_NAME=”wordpress” MYSQL_SSL_CA=”BaltimoreCyberTrustroot.crt.pem” |
Use a custom image for MySQL TLS/SSL and other configurations
By default, TLS/SSL is used by Azure Database for MySQL. WordPress requires additional configuration to use TLS/SSL with MySQL. The WordPress ‘official image’ doesn’t provide the additional configuration, but a custom image has been prepared for your convenience. In practice, you would add desired changes to your own image.
Changed Line#18
Updated Code:
Update app with new configuration
| Update app with new configuration: | az webapp config container set –resource-group myResourceGroup1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml |
Browse to the app
Browse to the deployed app at (http://<app-name>.azurewebsites.net). The app is now using Azure Database for MySQL.
Add persistent storage
Your multi-container is now running in Web App for Containers. However, if you install WordPress now and restart your app later, you’ll find that your WordPress installation is gone. This happens because your Docker Compose configuration currently points to a storage location inside your container. The files installed into your container don’t persist beyond app restart.
In this section, you’ll add persistent storage to your WordPress container.
Configure environment variables
To use persistent storage, you’ll enable this setting within App Service. To make this change, use the az webapp config appsettings set command in Cloud Shell. App settings are case-sensitive and space-separated.
To use persistent storage, you’ll enable this setting within App Service. To make this change, use the az webapp config appsettings set command in Cloud Shell. App settings are case-sensitive and space-separated.
| Add persistent storage | az webapp config appsettings set –resource-group myResourceGroup1 –name myappname-rk –settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=TRUE |
Modify configuration file
The volumes option maps the file system to a directory within the container. ${WEBAPP_STORAGE_HOME} is an environment variable in App Service that is mapped to persistent storage for your app. You’ll use this environment variable in the volumes option so that the WordPress files are installed into persistent storage instead of the container.
Make the following modifications to the file:
In the wordpress section, add a volumes option so it looks like the following code:
Update app with new configuration/Compose 🙂
| Update app with new configuration/Compose 🙂 | az webapp config container set –resource-group myResourceGroup1 –name myappname-rk –multicontainer-config-type compose –multicontainer-config-file docker-compose-wordpress.yml |
Browse to the app
The WordPress container is now using Azure Database for MySQL and persistent storage.
Conclusion
In conclusion, Azure App Service’s support for multi-container applications represents a significant advancement in cloud application deployment. It offers a robust platform for developers to deploy and manage containerized applications with ease and confidence, paving the way for innovative and scalable cloud solutions. 🚀🔐👨💻
References:
https://learn.microsoft.com/en-us/azure/app-service/tutorial-multi-container-app

