cannot access webapp running in docker

I followed a tutorial about creating a web-app using Docker. My dockerfile exposes port 5000:

FROM AS base

FROM AS build
COPY ["CustomerApi/CustomerApi.csproj", "CustomerApi/"]
COPY ["CustomerApi.Domain/CustomerApi.Domain.csproj", "CustomerApi.Domain/"]
COPY ["CustomerApi.Service/CustomerApi.Service.csproj", "CustomerApi.Service/"]
COPY ["CustomerApi.Data/CustomerApi.Data.csproj", "CustomerApi.Data/"]
RUN dotnet restore "CustomerApi/CustomerApi.csproj"
COPY . .
WORKDIR "./CustomerApi"
RUN dotnet build "CustomerApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CustomerApi.csproj" -c Release -o /app/publish

FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CustomerApi.dll"]

when I run the image locally using

docker run myrepo/demo:latest -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000

and open my browser on https://localhost:5000 I get ERR_EMPTY_RESPONSE (I’m not sure why I need 5001 within my docker run-command at all, as it’s not exposed within my dockerfile).

When I inspect the image within docker desktop I see this:

enter image description here

In particular it shows ASPNETCORE_URLS=http://+80, although I overwrote that above using -e ASPENTCORE_URLS=https://5000.

>Solution :

The options on docker run are split up in 2 parts:

  • Options before the image name are docker options
  • Options after the
    image name override any CMD and is sent to the container

So your command should look like this

docker run -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000 myrepo/demo:latest

EXPOSE doesn’t actually do anything. It’s mostly documentation about what ports you think the container uses. It can be wrong and if it’s wrong you don’t get any errors or warnings.

Leave a Reply