SBFrancies
SBFrancies

Reputation: 4250

Running alpine docker container deployed to Azure App Service does not respond to pings after deployment

I am trying to deploy a docker image running a C# .Net 6 Web API to an Azure App Service (for containers). The service currently works using FROM mcr.microsoft.com/dotnet/aspnet:6.0 base image but I want to change to alpine:3.19. The updated docker file looks like this:

# Build Stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app

COPY MyProject/MyProject.csproj ./MyProject/

RUN dotnet restore MyProject/MyProject.csproj

COPY MyProject/* ./MyProject/

RUN dotnet publish --configuration Release --output out MyProject/MyProject.csproj

# Unit Test Runner

FROM build as unit-tests

WORKDIR /app/MyProject.UnitTests

COPY MyProject.UnitTests/. .

ENTRYPOINT [ "dotnet", "test"]

# Integration Test Runner

FROM build as integration-tests

WORKDIR /app/MyProject.IntegrationTests

COPY MyProject.IntegrationTests/. .

ENTRYPOINT [ "dotnet", "test"]

# Run Stage
FROM alpine:3.19
RUN apk update \
    && apk upgrade \
    && apk add --no-cache dotnet6-runtime \
    && apk add --no-cache  aspnetcore6-runtime
WORKDIR /app
COPY --from=build /app/out .
# Allow SSH access
COPY entrypoint.sh ./
COPY sshd_config /etc/ssh/
RUN apk update \
    && apk upgrade \
    && apk add --no-cache bash \
    && apk add --no-cache openssh \
    && apk add --no-cache tini \
    && apk add --no-cache netcat-openbsd \
    && echo "root:Docker!" | chpasswd \
    && chmod u+x ./entrypoint.sh \
    && cd /etc/ssh/ \
    && ssh-keygen -A

ENV PORT 80
EXPOSE 80
EXPOSE 443
EXPOSE 2222

ENTRYPOINT ["/sbin/tini", "--"]

CMD ["./entrypoint.sh"]

entrypoint.sh looks like this:

#!/bin/bash
set -e
#--- Starting SSH
/usr/sbin/sshd
exec dotnet MyProject.dll

When I deploy to the app service the container starts up. I can tell this from the logs which show a background service running. The issue is that the container seems to be inaccessible via port 80. The web app start up process gives off logs like this:

Waiting for response to warmup request for container app_my-project_1_3addd53d. Elapsed time = 30.5399342 sec

Before eventually failing:

2023-12-13T02:18:20.920Z ERROR - Container app_my-project_1_3addd53d didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging. 2023-12-13T02:18:20.970Z INFO - Stopping site app_my-project_1 because it failed during startup.

I have tried setting the following appsetting:

WEBSITES_PORT = 80

It has not made a difference. From the logs I can see it is the following docker command which is run:

docker run -d --expose=80 --name app_my-project_1_3addd53d -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8080 -e WEBSITE_SITE_NAME=app_my-project -e WEBSITE_AUTH_ENABLED=False -e PORT=8080 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=app_my-project.azurewebsites.net -e WEBSITE_INSTANCE_ID=2f7d09e6f18b384667ff962cc75fe4cbeb8ff744d3ba3c5cc3766bd82eb68007 -e HTTP_LOGGING_ENABLED=1 myregistry.azurecr.io/app_my-project:tag 

Upvotes: 0

Views: 461

Answers (1)

SBFrancies
SBFrancies

Reputation: 4250

Found it!

I needed to add the following to my Dockerfile:

ENV ASPNETCORE_URLS=http://+:80

Upvotes: 0

Related Questions