Dennis Stuhr
Dennis Stuhr

Reputation: 71

.NET 6 Linux multicontainer app not cannot establish container inter-communication in Azure App Service

I cannot for the life of me get my Azure App Service multicontainer app with 3 containers working, where they can communicate with each other. I've tried for the better part of a week without any luck...

It's a .NET 6 app written in C# with 3 containers deployed - a web app, a Redis server and a MSSQL server - using Docker Compose and Azure DevOps. Deployment works as expected, but the web app fails because it cannot establish a connection to either the Redis server (using port 6379) or the MSSQL server (using port 1433)

The Docker Compose file looks something like this:

services:
  website:
    image: <registryname>.azurecr.io/<containername>:latest
    container_name: web
    restart: always
    build:
      context: .
      dockerfile: Presentation/<WebProject>/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
  db:
    image: mcr.microsoft.com/mssql/server:2019-latest
    container_name: db
    ports:
      - "1433:1433"
    volumes:
      - mssql:/var/opt/mssql/data
    environment:
      SA_PASSWORD: "<password>"
      ACCEPT_EULA: "Y"
  redis:
    image: <registryname>.azurecr.io/redis:7.0.4
    command: redis-server --requirepass <redisPassword>
    ports:
     - "6379:6379"
    volumes:
     -  redis_data:/var/lib/redis
    environment:
     - REDIS_REPLICATION_MODE=master

volumes:
  mssql:
    external: true
  redis_data:
    driver: local

And the deployment YAML file looks something like this:

trigger:
  branches:
   include:
     - 'master'
  paths:
   include:
     - Presentation/<WebProject>/*
   exclude:
     - Presentation/<ApiProject>/*

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  azureContainerRegistry: '{"loginServer": "<registryname>.azurecr.io", "id": "/subscriptions/<subscription-id>/resourcegroups/<resourcegroup>/providers/Microsoft.ContainerRegistry/registries/<registryname>"}'
  azureSubscription: '<Name of service connection to Azure Resource Manager>'
  appName: <Azure app service app name>
  imageRepository: '<image name in registry>'
  containerRegistry: '<regsitryname>.azurecr.io'
  tag: latest

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: DockerCompose@0
      displayName: 'Build images'
      inputs:
        containerregistrytype: Azure Container Registry
        azureContainerRegistry: $(azureContainerRegistry)
        azureSubscription: $(azureSubscription)
        dockerComposeFile: 'docker-compose-web-azure.yml'
        action: Build services
        arguments: website
    - task: DockerCompose@0
      displayName: 'Push images'
      inputs:
        containerregistrytype: Azure Container Registry
        azureContainerRegistry: $(azureContainerRegistry)
        azureSubscription: $(azureSubscription)
        dockerComposeFile: 'docker-compose-web-azure.yml'
        action: Push services
        includeSourceTags: true
        includeLatestTag: false
    - task: AzureWebAppContainer@1
      displayName: 'Azure Web App on Container Deploy'
      inputs:
        azureSubscription: $(azureSubscription)
        appName: $(appName)
        imageName: $(containerRegistry)/$(imageRepository):$(tag)
        multicontainerConfigFile: 'docker-compose-web-azure.yml'

All containers starts up as expected with no errors in the logs.

I've modified my Dockerfile for the web project so that I can SSH into the container from Azure App Service and test connectivity to other containers using telnet. Example:

telnet localhost 1433
telnet 127.0.0.1 1433

And a bunch of other stuff. Nothing works.

Am I better off using an Azure VM (where I can at least control everything, including Docker networks which I use on my own machine), or is there a solution to this?

Upvotes: 1

Views: 74

Answers (1)

Dennis Stuhr
Dennis Stuhr

Reputation: 71

Oh my 'effin god... I've literally spent a week trying to figure this out, scouring the internet, reading dozens upon dozens of articles, questions and answers, coming up with NOTHING. Tried gods know what within the Azure Portal with various network settings, but kept getting NOTHING.

Within 30 minutes of posting this question, I decided to look in the logs and it dawned on me try one more thing. And it worked!

Solution was to use the service name from the Docker Compose file when making the connection. This works in telnet, in the connection string in the web app, so the site is also now functional:

telnet db 1433
telnet redis 6379

I feel kinda stupid. But, I hope this will help some other poor chap and spare a week of frustration!

Upvotes: 1

Related Questions