I'm getting an odd, intermittent issue with deploying a C# azure function on a docker container to my azure instance. The container takes a long time to start then fails to get a response after pinging port 8080. This causes my azure function to timeout.
I checked out the log files and noticed that the docker -run command is starting port 8181.
Below is the docker log file.
2024-04-23T01:12:24.211Z INFO - Pulling image: mcr.microsoft.com/appsvc/middleware:stage5
2024-04-23T01:12:24.363Z INFO - stage5 Pulling from appsvc/middleware
2024-04-23T01:12:24.376Z INFO - Digest: sha256:727d0ba73b65d90f698063ada9d4e8a097afff3fa0d7ed57b29869071cbcde47
2024-04-23T01:12:24.378Z INFO - Status: Image is up to date for mcr.microsoft.com/appsvc/middleware:stage5
2024-04-23T01:12:24.396Z INFO - Pull Image successful, Time taken: 0 Seconds
2024-04-23T01:12:24.408Z INFO - Starting container for site
2024-04-23T01:12:24.409Z INFO - docker run -d --expose=8181 --name datafeed-qa_1_1d67ee29_middleware -e WEBSITE_CORS_ALLOWED_ORIGINS=https://portal.azure.com -e WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=datafeed-qa -e WEBSITE_AUTH_ENABLED=False -e PORT=8181 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME={my hostname}WEBSITE_INSTANCE_ID={my instance id}mcr.micro2024-04-23T01:12:24.968Z INFO - Initiating warmup request to container datafeed-qa_1_1d67ee29 for site datafeed-qa
2024-04-23T01:12:55.341Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 30.3731551 sec
2024-04-23T01:13:10.416Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 45.4478631 sec
2024-04-23T01:13:29.480Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 64.5122839 sec
2024-04-23T01:13:45.970Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 81.0025027 sec
2024-04-23T01:14:01.036Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 96.0683764 sec
2024-04-23T01:14:17.049Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 112.0812039 sec
2024-04-23T01:14:33.032Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 128.0643914 sec
2024-04-23T01:14:48.532Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 143.5636517 sec
2024-04-23T01:15:06.026Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 161.0576989 sec
2024-04-23T01:15:21.101Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 176.1327163 sec
2024-04-23T01:15:36.174Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 191.2058092 sec
2024-04-23T01:15:51.246Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 206.2775529 sec
2024-04-23T01:16:07.552Z INFO - Waiting for response to warmup request for container datafeed-qa_1_1d67ee29. Elapsed time = 222.5838858 sec
2024-04-23T01:16:15.605Z ERROR - Container datafeed-qa_1_1d67ee29 for site datafeed-qa did not start within expected time limit. Elapsed time = 230.6369165 sec
2024-04-23T01:16:15.605Z INFO - Initiating warmup request to container datafeed-qa_1_1d67ee29_middleware for site datafeed-qa
2024-04-23T01:16:17.503Z INFO - Container datafeed-qa_1_1d67ee29_middleware for site datafeed-qa initialized successfully and is ready to serve requests.
2024-04-23T01:16:17.509Z ERROR - Container datafeed-qa_1_1d67ee29 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2024-04-23T01:16:22.509Z INFO - Stopping site datafeed-qa because it failed during startup.
Why is this log file specifying to use port 8181? The azure function itself is trying to ping port 8080 and my docker file specifically exposes port 8080.
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DatafeedAPI/DataFeedAPI.csproj", "DatafeedAPI/"]
COPY ["DataFeedAPI.Infrastructure/DataFeedAPI.Infrastructure.csproj", "DataFeedAPI.Infrastructure/"]
COPY ["DataFeedAPI.Models/DataFeedAPI.Models.csproj", "DataFeedAPI.Models/"]
RUN dotnet restore "./DatafeedAPI/./DataFeedAPI.csproj"
COPY . .
WORKDIR "/src/DatafeedAPI"
RUN dotnet build "./DataFeedAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./DataFeedAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
This app service plan has several azure functions on it that also are deployed through docker containers. Is there a possibility that port 8080 is taken and the docker container knows but azure does not?
I tried setting the WEBSITES_PORT, PORT, and WEBSITES_CONTAINER_START_TIME_LIMIT values in my azure app service configuration and have found nothing changes that port 8181.
I tried setting the WEBSITES_PORT, PORT, and WEBSITES_CONTAINER_START_TIME_LIMIT values in my azure app service configuration and have found nothing changes that port 8181.
Thanks for the Insights @DazWilkin.
Dockerfile correctly exposes the port that the Azure Function listens on. Change YourFunctionApp.dll
with the actual entry point for the Azure Function.
# Use Azure Functions base image
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
WORKDIR /home/site/wwwroot
# Expose port 8080 for Azure Function
EXPOSE 8080
# Copy and publish Azure Function application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DatafeedAPI/DataFeedAPI.csproj", "DatafeedAPI/"]
COPY ["DataFeedAPI.Infrastructure/DataFeedAPI.Infrastructure.csproj", "DataFeedAPI.Infrastructure/"]
COPY ["DataFeedAPI.Models/DataFeedAPI.Models.csproj", "DataFeedAPI.Models/"]
RUN dotnet restore "./DatafeedAPI/./DataFeedAPI.csproj"
COPY . .
WORKDIR "/src/DatafeedAPI"
RUN dotnet build "./DataFeedAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
# Final stage for Azure Function deployment
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=build /app/publish .
# Set environment variables
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
8080
.WEBSITES_PORT
environment variable to 8080
in Azure App Service configuration.