locked
Can't get a ASP.Net Core Docker Image to run in Azure Linux Container Web App RRS feed

  • Question

  • I have been trying for several days to get an Azure Linux Container Web App to run. I have a web site frontend built in Angular and an asp.net core 3.1 backend that this all runs in, and I have a Dockerfile that builds it all.

    The angular site is hosted from within asp.net core wwwroot folder.

    I can run the app standalone with no problems. I can also run it in Docker desktop with no issues.

    docker build MyApp -t myapp
    docker run -d -p 80:80 myapp:latest -e environment='Production' -e ASPNETCORE_ENVIRONMENT='Production'

    This is my Dockerfile

    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
    WORKDIR /src
    COPY ["Backend", "backend"]
    RUN dotnet restore "backend/src/myapp.Web/myapp.Web.csproj"
    COPY . .
    WORKDIR "backend/src/myapp.Web"
    RUN dotnet build "myapp.Web.csproj" -c Release -o /app/build
    
    # Angular
    FROM node:12.2.0 as angular
    WORKDIR /src
    ENV PATH /app/node_modules/.bin:$PATH
    
    COPY ["Frontend/myapp-frontend-v2", "frontend"]
    RUN npm install -g @angular/cli
    WORKDIR /src/frontend 
    RUN npm install
    RUN ng build --prod --output-path=/app/dist
    
    # Publish
    FROM build AS publish
    RUN dotnet publish "myapp.Web.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    COPY --from=angular /app/dist /app/wwwroot
    
    ENTRYPOINT ["dotnet", "myapp.Web.dll"]

    I am then building this dockerfile in Devops with a .yml pipeline and pushing to an Azure ACR with:
    steps:
    - task: Docker@2
      displayName: Build And Push
      inputs:
        containerRegistry: $(dockerRegistryServiceConnection)
        repository: $(imageName)
        Dockerfile: $(dockerFile)
        tags: 'myapp'

    This also works and I can see it being pushed to the Azure Container Registry.

    I then restart the Azure Web App so that it restarts with the latest image and get the following in the console.

    2020-04-21 06:39:30.400 INFO  - Pulling image: acrmyapp.azurecr.io/myapp-web:myapp
    2020-04-21 06:39:31.736 INFO  - myapp Pulling from myapp-web
    2020-04-21 06:39:31.738 INFO  -  Digest: sha256:f64056681fdc66939b362196a3293aea9baa311340293c17664c36d77088a49d
    2020-04-21 06:39:31.740 INFO  -  Status: Image is up to date for acrmyapp.azurecr.io/myapp-web:bt
    2020-04-21 06:39:31.745 INFO  - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
    2020-04-21 06:39:31.775 INFO  - Starting container for site
    2020-04-21 06:39:31.776 INFO  - docker run -d -p 4880:80 --name web-prod-bt_0_e32966d1 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=web-prod-bt -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=web-prod-bt.azurewebsites.net -e WEBSITE_INSTANCE_ID=5c117bc5116941ff3fb1eb90511ac2f83e1adddea111b14577d6ea1fb7356b3d -e HTTP_LOGGING_ENABLED=1 acrmyapp.azurecr.io/myapp-web:bt -e WEBSITES_PORT=80 -e environment='Production' -e ASPNETCORE_ENVIRONMENT='Production'
    2020-04-21 06:39:32.904 INFO  - Initiating warmup request to container web-prod-bt_0_e32966d1 for site web-prod-bt
    
    2020-04-21 06:39:34.954 ERROR - Container web-prod-bt_0_e32966d1 for site web-prod-bt has exited, failing site start
    2020-04-21 06:39:34.957 ERROR - Container web-prod-bt_0_e32966d1 didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.
    2020-04-21 06:39:34.968 INFO  - Stoping site web-prod-bt because it failed during startup.

    If I run the same command locally in Docker Desktop (On windows 10), just replacing the source of the image, it works.

    docker run -d -p 4880:80 --name web-prod-bt_0_e32966d1 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=web-prod-bt -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=web-prod-bt.azurewebsites.net -e WEBSITE_INSTANCE_ID=5c117bc5116941ff3fb1eb90511ac2f83e1adddea111b14577d6ea1fb7356b3d -e HTTP_LOGGING_ENABLED=1 acrmyapp.azurecr.io/myapp-web:bt -e WEBSITES_PORT=80 -e environment='Production' -e ASPNETCORE_ENVIRONMENT='Production'

    I have found other threads concerning this such as:

    I have tried both adding the -e PORT=80 and making sure to only have linux style line feeds in the Dockerfile. The asp net core app also only exposes HTTP (and does not require HTTPS or try to redirect to it), and again all this works locally in Docker Desktop.

    Nothing I have tried has made any difference at all so far. The Azure Web App simply refuses to start.

    My best guess right now is that Azure tries to verify that the container is running in some manner that I don't understand and fails at doing so and stops the service.

    I really need some help with this.

    Thank you.

    • Edited by VoSSer Wednesday, April 22, 2020 8:10 AM
    Wednesday, April 22, 2020 8:00 AM

All replies

  • I figured it out.

    The error was in these paramaters:

    -e environment='Production' -e ASPNETCORE_ENVIRONMENT='Production'

    They have to be specified without ', this works:

    -e environment=Production -e ASPNETCORE_ENVIRONMENT=Production

    I originally also specified -e WEBSITES_PORT=80 in the Container Startup script, it was not needed.

    Wednesday, April 22, 2020 12:44 PM
  • Glad to know that you got it working. Thanks for sharing the solution that helped, it would benefit other users with a similar issue.
    If there is any specific questions on this topic, please let us know we will be more than happy to assist you further. Appreciate the follow-up.

    To keep you posted.

    We're migrating from MSDN to Microsoft Q&A as our new forums and Azure WebApps has already made the move!  
    In future, you can ask and look for the discussion for Azure WebApps related questions on the respective forums: 
    https://docs.microsoft.com/answers/topics/azure-webapps.html  Note: Since this thread did not land in the right forum it would be moved to the appropriate forum.

    We are actively working to onboard remaining Azure services on Microsoft Q&A.

    We will make a public announcement once complete. 
    Want to Learn more about new platform, see Microsoft Q&A Getting Started:
    https://docs.microsoft.com/answers/articles/388/microsoft-qa-frequently-asked-questions.html


    Monday, April 27, 2020 8:48 AM