I am learning about azure and github ci/cd with simple docker-compose setup which is running perfectly on my dev machine but is constantly failing on Azure WebApp with below Errors:
2024-09-04T16:12:01.352714815Z The command could not be loaded, possibly because:
2024-09-04T16:12:01.352738315Z * You intended to execute a .NET application:
2024-09-04T16:12:01.352775915Z The application 'foo.dll' does not exist.
2024-09-04T16:12:01.352781015Z * You intended to execute a .NET SDK command:
2024-09-04T16:12:01.352784615Z No .NET SDKs were found.
2024-09-04T16:12:01.352787915Z
2024-09-04T16:12:01.352790915Z Download a .NET SDK:
2024-09-04T16:12:01.352794015Z https://aka.ms/dotnet/download
2024-09-04T16:12:01.352797215Z
2024-09-04T16:12:01.352800215Z Learn about SDK resolution:
2024-09-04T16:12:01.352806415Z https://aka.ms/dotnet/sdk-not-found
On further checking logs in Deployment Center/Container Logs, I observed that WebApp internally doesn’t even call docker-compose up to start the containers which works perfectly fine on my dev machine but instead runs below commands:
2024-09-04T16:20:41.519Z INFO - Starting multi-container app..
2024-09-04T16:20:42.049Z INFO - Pulling image: bar.azurecr.io/web:latest
2024-09-04T16:20:42.218Z INFO - latest Pulling from web
2024-09-04T16:20:42.265Z INFO - Digest: sha256:<redacted>
2024-09-04T16:20:42.265Z INFO - Status: Image is up to date for bar.azurecr.io/web:latest
2024-09-04T16:20:42.279Z INFO - Pull Image successful, Time taken: 0 Seconds
2024-09-04T16:20:42.339Z INFO - Starting container for site
2024-09-04T16:20:42.340Z INFO - docker run -d -p 6733:5104 --name foo_web-app_0_871e06a6 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=true -e WEBSITE_SITE_NAME=foo -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=foo.azurewebsites.net -e WEBSITE_INSTANCE_ID=<some_id> bar.azurecr.io/web:latest
2024-09-04T16:20:42.341Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2024-09-04T16:20:42.887Z INFO - Pulling image: bar.azurecr.io/db:latest
2024-09-04T16:20:43.082Z INFO - latest Pulling from db
2024-09-04T16:20:43.141Z INFO - Digest: sha256:<redacted>
2024-09-04T16:20:43.142Z INFO - Status: Image is up to date for bar.azurecr.io/db:latest
2024-09-04T16:20:43.154Z INFO - Pull Image successful, Time taken: 0 Seconds
2024-09-04T16:20:43.212Z INFO - Starting container for site
2024-09-04T16:20:43.213Z INFO - docker run -d --expose=1433 --name foo_db_0_871e06a6 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=true -e WEBSITE_SITE_NAME=foo -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=foo.azurewebsites.net -e WEBSITE_INSTANCE_ID=<some_id> bar.azurecr.io/db:latest
2024-09-04T16:20:43.214Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
My sample Docker-Compose file
name: sample-app
services:
web-app:
image: bar.azurecr.io/web:latest
environment:
- ConnectionStrings__DefaultConnection=Server=db;Database=${DbName};User Id=${UserName};Password=${Password};MultipleActiveResultSets=true; TrustServerCertificate=true
ports:
- "80:5104"
volumes:
- ${WEBAPP_STORAGE_HOME}/app_data:/app
networks:
- isolated_network
depends_on:
- db
db:
image: bar.azurecr.io/db:latest
ports:
- "1433:1433"
networks:
- isolated_network
volumes:
- ${WEBAPP_STORAGE_HOME}/db_data:/var/opt/mssql
networks:
isolated_network:
driver: bridge
My GitHub Workflow file:
name: Build and deploy ASP.Net Core app to an Azure Web App
env:
ACR_NAME: bar
AZURE_WEBAPP_NAME: foo
AZURE_WEBAPP_PACKAGE_PATH: '.'
on:
push:
branches: [ "main" ]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Log in to Azure Container Registry
run: |
az acr login -n ${{ env.ACR_NAME }}
- name: Build and push Web image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.ACR_NAME }}.azurecr.io/web:latest
- name: Build and push Db image
uses: docker/build-push-action@v2
with:
context: .
file: ./DockerDbfile
push: true
tags: ${{ env.ACR_NAME }}.azurecr.io/db:latest
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
configuration-file: 'docker-compose.yml'
My questions are:
- Considering that I am using github workflows to build the image, push it to acr and then running docker-compose on webapp all hosted in same subscription, is there a better way to do this?
- Any idea on how to troubleshoot the current setup further as this is a very simple use case with .net MVC Core application as web and sqlserver as db all running on docker.
- Why did the WebApp not run docker-compose up in container logs 🙂
I created a sample multi container application with docker compose and deployed to the ACR via GitHub.
-
I’ve referred this doc and created the application.
-
Thanks @alaintd for clear explanation I’ve referred this doc to build and push the docker image to Azure Container registry using GitHub actions.
-
Make sure you add your Azure container registry credentials in GitHub repository settings -> secrets and variables ->actions -> New repository secret.
-
I’ve added the below lines of code to my workflow file to login to Azure container registry.
name: Azure Container Registry Login
uses: Azure/docker-login@v1
with:
login-server: multiappregis.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
My complete workflow file :
name: Build and Push Docker Images
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Azure Container Registry Login
uses: Azure/docker-login@v1
with:
login-server: multiappregis.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Build and push the first image (app)
uses: docker/build-push-action@v2
with:
context: ./multiapp
file: ./multiapp/Dockerfile
push: true
tags: <ACR-NAME>.azurecr.io/app:latest
- name: Build and push the second image (db)
uses: docker/build-push-action@v2
with:
context: ./multiapp
file: ./multiapp/Dockerdb/Dockerfile
push: true
tags: <ACR-NAME>.azurecr.io/db:latest
- After successfully deploying the images to Azure Container Registry via GitHub Actions.
- I further deployed the application to Azure App Service using Azure Container Registry
Output:
4