Deploying .NET 8 Docker images to Azure Container Instances

Alejo Millo 20 Reputation points
2024-03-29T00:49:54.0833333+00:00

Hello, I'm having trouble to deploy an .NET 8 Web App Docker container image to an Azure Container Instance.

This is my Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base

USER app

WORKDIR /app

EXPOSE 8080

EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

ARG BUILD_CONFIGURATION=Release

WORKDIR /src

COPY ["AzureWebAppTest/AzureWebAppTest.csproj", "AzureWebAppTest/"]

RUN dotnet restore "./AzureWebAppTest/AzureWebAppTest.csproj"

COPY . .

WORKDIR "/src/AzureWebAppTest"

RUN dotnet build "./AzureWebAppTest.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish

ARG BUILD_CONFIGURATION=Release

RUN dotnet publish "./AzureWebAppTest.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final

WORKDIR /app

COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "AzureWebAppTest.dll"]

I know that in .NET 8 the default port changed to 8080 and that I have to tell my container to map port 80 to the port 8080 but in Azure Container Instance I do not see a "target port" option as there is for example in Container Apps, besides, although the base .NET 8 image set the ASPNETCORE_HTTP_PORTS to 8080 it seems to not be working since once the ACI is running, I tried to access via the public dns name label and I get a "Connection reset" on my browser.

Thank you.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
636 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,167 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anveshreddy Nimmala 2,305 Reputation points Microsoft Vendor
    2024-03-29T06:10:16.41+00:00

    Hello Alejo Millo

    Welcome to microsoft Q&A, Thankyou for posting your query here.

    Your Dockerfile looks good for a .NET 8 app. You've opened up ports 8080 and 8081 the right way, just like how .NET 8 needs it.

    Azure Container Instances (ACI) doesn't let you pick a specific "target port".

    you can get your ports set up the way you need with the help of Azure's command-line tools.

    Make sure you're signed into your Azure account with the command line tool by typing az login.

    Then, you'll use the az container create command to make your container with the right ports.

    az container create \

    --resource-group <RESOURCEGROUP NAME> \

    --name <ContainerName> \

    --image <Image> \

    --dns-name-label <DnsName> \

    --ports 8080 \

    --environment-variables ASPNETCORE_URLS="http://+:8080" \

    --protocol TCP

    If, after setting everything up, you're still having trouble connecting (like getting "Connection reset" errors),:

    Use Azure's website or the command line tool to check your container's logs for any errors during startup.

    Check to make sure no network security settings or firewalls are blocking the ports you're using.

    If you've just set up a friendly DNS name for your container, give it a bit of time to start working everywhere.

    Hope this helps you.

    If an answer has been helpful, please consider accepting the answer to help increase visibility of this question for other members of the Microsoft Q&A community. If not, please let us know what is still needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    f52a2e1b-47f1-4468-81ef-8f899197a2e9

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful