azuredocker.net-coredockerfileazure-web-app-service

How does Azure App Service manage port binding with docker container? Does it recognize Expose?


I just deployed a docker image from azure cr to azure app service.

The docker image contains a .net core API. This is the dockerfile:

#Running aspnet core 3.1 runtime on ubuntu 20.04
FROM mcr.microsoft.com/dotnet/aspnet:3.1.14-focal
EXPOSE 5000

ENV ASPNETCORE_URLS="http://0.0.0.0:5000"

COPY myapi/bin/Release/netcoreapp3.1/publish/ api/
WORKDIR /api    
ENTRYPOINT [ "dotnet", "myapi.dll"]

This API is listening on port 5000, and I haven't given this information to Azure in any way, except with the EXPOSE command in the dockerfile. And yet, I can access myapi correctly from the url azure gave me, using port 443. I'm surprised this is working.

Is Azure detecting the EXPOSE command in my docker file? Or what is it that makes this work?


Solution

  • I had the same question and I found the answer here: https://learn.microsoft.com/en-us/answers/questions/447302/access-multiple-ports-in-docker-compose-azure-web.html

    In short Azure Website do the job for you if you don't

    Quote: Azure App Service only exposes ports 80 and 443. Yes, incoming requests from client would just be over 443/80 which should be mapped to the exposed port of the container. App Service will attempt to detect which port to bind to your container, but you can also use the WEBSITES_PORT app setting and configure it with a value for the port you want to bind to your container.