[Windows Containers] Unable to start container. Error message: Index was outside the bounds of the array

AdamStachowicz-8288 101 Reputation points
2021-07-05T16:55:10.283+00:00

Hello,

I have Windows App Service in Azure (Docker image: mcr.microsoft.com/dotnet/sdk:5.0) with .NET 5 and I can't start container. Docker image is working correctly on my machine (Windows 10).

Repository: https://github.com/Saibamen/dotnet5-webjob-docker

Log stream from App Service:

05/07/2021 11:02:33.454 INFO - Site: MYWebJob - Creating container image05/07/2021 11:02:33.465 INFO - Site: MYWebJob - Verifying container image and pull image if necesary05/07/2021 11:02:33.465 INFO - Site: MYWebJob - Pulling container image: mycontainers.azurecr.io/dev/mywebjob:latest using credentials.05/07/2021 11:02:33.465 INFO - Site: MYWebJob - Pulling from custom registry: https://mycontainers.azurecr.io05/07/2021 11:02:33.465 INFO - Site: MYWebJob - Pulling image using registry credentials
05/07/2021 11:02:33.565 INFO - Site: MYWebJob - Image: mycontainers.azurecr.io/dev/mywebjob:latestStatus: latest Pulling from dev/mywebjob
05/07/2021 11:02:33.574 INFO - Site: MYWebJob - Image: mycontainers.azurecr.io/dev/mywebjob:latestStatus:  Digest: sha256:d76d66c8a380a7e8f71f8e157f3820674f51e97e1400cbe0775ecc6c3a02b269
05/07/2021 11:02:33.575 INFO - Site: MYWebJob - Image: mycontainers.azurecr.io/dev/mywebjob:latestStatus:  Status: Image is up to date for mycontainers.azurecr.io/dev/mywebjob:latest

05/07/2021 11:02:33.623 INFO - Site: MYWebJob - Purging pending logs after stopping container05/07/2021 11:02:33.623 INFO - Site: MYWebJob - Attempting to stop container: . Site MYWebJob05/07/2021 11:02:33.631 INFO - Site: MYWebJob - Purging after container failed to start05/07/2021 11:02:33.631 ERROR - Site: MYWebJob - Unable to start container. Error message: Index was outside the bounds of the array.

2021-07-05 11:02:33 ~1MYWEBJOB GET / - 80 - 10.0.32.21 AlwaysOn - - mywebjob.azurewebsites.net 200 0 0 2697 489 9
2021-07-05 11:02:33 MYWEBJOB GET / - 80 - 10.0.32.21 AlwaysOn ARRAffinity=2b87b1c25b5b9581cbfc4a0595c9550228d4534986743abaa523c8e4d524807d - MYWebJob 409 49 64 156398 759 316
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
648 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,997 questions
{count} vote

Accepted answer
  1. AdamStachowicz-8288 101 Reputation points
    2021-07-22T13:09:13.09+00:00

    Thanks @Mike Zuber

    The issue was that SDK image (mcr.microsoft.com/dotnet/sdk:5.0) always failing in Azure environment.

    Now I’m using mcr.microsoft.com/dotnet/runtime:5.0, but runtime images don’t have PowerShell (see https://github.com/dotnet/dotnet-docker/issues/2984 how I fixed it)

    All Web Jobs are now running in Azure, with PowerShell entrypoint.

    @Mike Zuber please consider using mcr.microsoft.com/dotnet/runtime:5.0 image if you want to have (a lot) smaller image size

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Mike Zuber 6 Reputation points
    2021-07-14T19:05:10.373+00:00

    I managed to fix my issue by switching to a new base image.

    This is my first Dockerfile, which resulted in the " Unable to start container. Error message: Index was outside the bounds of the array." error:

    # escape=`
    
    FROM mcr.microsoft.com/dotnet/aspnet:5.0-windowsservercore-ltsc2019 AS base
    
    # Set environment vars for the next step.
    ENV `
        # Unset ASPNETCORE_URLS from aspnet base image
        ASPNETCORE_URLS= `
        DOTNET_SDK_VERSION=5.0.301 `
        # Enable correct mode for dotnet watch (only mode supported in a container)
        DOTNET_USE_POLLING_FILE_WATCHER=true `
        # Skip extraction of XML docs - generally not useful within an image/container - helps performance
        NUGET_XMLDOC_MODE=skip
    
    # Download and install the dotnet core SDK for x86. This also includes the runtime.
    RUN powershell -Command "`
     $ErrorActionPreference = 'Stop'; `
     $ProgressPreference = 'SilentlyContinue'; `
     `
     Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.azureedge.net/dotnet/Sdk/$Env:DOTNET_SDK_VERSION/dotnet-sdk-$Env:DOTNET_SDK_VERSION-win-x86.zip; `
     $dotnet_sha512 = '8fd4b4e00d5506e12a3b214ce9f4142fef42f304d01c359f5551baba7e327768daaf236edf899be83f5cd87d36c9234b8329e97355fc5ea41cb5c903740ea5ed'; `
     if ((Get-FileHash dotnet.zip -Algorithm sha512).Hash -ne $dotnet_sha512) { `
     Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
     exit 1; `
     }; `
            `
     $install_path = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath dotnet; `
     New-Item -Force -Path $install_path -ItemType directory | Out-Null; `
     Write-Host "Installing dotnet x86 to $install_path"; `
     tar -C $install_path -oxzf dotnet.zip; `
     Remove-Item -Force dotnet.zip;"
    
    EXPOSE 80
    
    # Copy 32-bit ODBC driver files over
    COPY ["./OdbcDrivers/*", "c:/Program Files (x86)/OdbcDrivers/"]
    
    # Copy the ODBC driver registry file and run it to register the drivers with ODBC.
    COPY ["./OdbcDrivers/RegKeys.reg", "c:/Program Files (x86)/OdbcDrivers/"]
    RUN ["reg", "import", "c:/Program Files (x86)/OdbcDrivers/OdbcDrivers.reg"]
    
    ADD ./OurWebApi /App
    WORKDIR /App
    ENTRYPOINT ["c:/Program Files (x86)/dotnet/dotnet", "OurWebApi.dll"]
    

    For what it's worth: I even changed the ENTRYPOINT above to just "cmd.exe" and I still got the "Index was outside the bounds of the array." error. So, our WebApi application didn't appear to be a factor.

    My 2nd Dockerfile, which worked:

    # escape=`
    
    ARG REPO=mcr.microsoft.com/dotnet/runtime
    FROM $REPO:5.0-windowsservercore-ltsc2019 AS base
    
    # Set environment vars for the next step.
    ENV ASPNET_VERSION=5.0.8
    
    # Download and install the .NET Core Runtime for x86.
    RUN powershell -Command `
            $ErrorActionPreference = 'Stop'; `
            $ProgressPreference = 'SilentlyContinue'; `
            `
            Invoke-WebRequest -OutFile aspnetcore.zip https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/aspnetcore-runtime-$Env:ASPNET_VERSION-win-x86.zip; `
            $aspnetcore_sha512 = '990de1faf7f1c916a62fe15b87e2a7170238407882b2fb12d277a48a75120929296bf35c2deaf5690206f8295382767e220e92576ea73fab57f019023a132950'; `
            `
            if ((Get-FileHash aspnetcore.zip -Algorithm sha512).Hash -ne $aspnetcore_sha512) { `
                Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
                exit 1; `
            }; `
            `
            # Commented out because the Azure App Service doesn't like paths with spaces for some reason
     #$install_path = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath dotnet; `
            $install_path = 'C:\dotnet_x86'; `
     $null = New-Item -Force -Path $install_path -ItemType directory; `
     tar -C $install_path -oxzf aspnetcore.zip; `
     Remove-Item -Force aspnetcore.zip;"
    
    EXPOSE 80
    
    # Copy 32-bit ODBC driver files over
    COPY ["./OdbcDrivers/*", "c:/Program Files (x86)/OdbcDrivers/"]
    
    # Copy the ODBC driver registry file and run it to register the drivers with ODBC.
    COPY ["./OdbcDrivers/RegKeys.reg", "c:/Program Files (x86)/OdbcDrivers/"]
    RUN ["reg", "import", "c:/Program Files (x86)/OdbcDrivers/OdbcDrivers.reg"]
    
    ADD ./OurWebApi /App
    WORKDIR /App
    
    # Commented out because the Azure App Service doesn't like paths with spaces for some reason
    # See $install_path above as well
    #ENTRYPOINT ["c:/Program Files (x86)/dotnet/dotnet", "OurWebApi.dll"]
    
    ENTRYPOINT ["c:/dotnet_x86/dotnet", "OurWebApi.dll"]
    

    For context: We have a 32-bit WebAPI written using aspnetcore 5.0. It has to be 32-bit because the ODBC driver we're relying on is 32-bit as well. This is why we download the x86 SDK / runtime in the Dockerfile.

    1 person found this answer helpful.
    0 comments No comments