aspnetcore: [.NET 8] ASP.NET Core Web API Server is Not Accessible in Docker

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi,

I created a clean, default ASP.NET Core Web API project. The project name is “WebApplication4”. I didn’t change a thing in the project. So, everything is intact. I ran this project in release mode & docker. No problem until this point. I closed the docker container and tried to rerun the docker image using command line. My command was docker run -it -p 8080:8080 webapplication4:latest . I tried to access https://localhost:8080/swagger and https://localhost:8080/swagger/index.html. However, none of them is opening and I got an error like this ERR_SSL_PROTOCOL_ERROR.

To fix this, I cleaned all SSL protocols defined before and redefined it by trusting. It did not help. No change in the behaviour.

-> dotnet dev-certs https --clean -> dotnet dev-certs https

This behavior did not happen before until I updated my visual studio for .net 8.

The docker file is:

#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/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApplication4/WebApplication4.csproj", "WebApplication4/"]
RUN dotnet restore "./WebApplication4/./WebApplication4.csproj"
COPY . .
WORKDIR "/src/WebApplication4"
RUN dotnet build "./WebApplication4.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApplication4.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

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

The launchSettings.json file is:

{
  "profiles": {
    "http": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "http://localhost:5117"
    },
    "https": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "https://localhost:7099;http://localhost:5117"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "environmentVariables": {
        "ASPNETCORE_HTTPS_PORTS": "8081",
        "ASPNETCORE_HTTP_PORTS": "8080"
      },
      "publishAllPorts": true,
      "useSSL": true
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:15057",
      "sslPort": 44358
    }
  }
}

Expected Behavior

https://localhost:8080/swagger url should have been accessed successfully after running the docker from command line.

Steps To Reproduce

-> Open Visual Studio 17.8.0. -> Create a ASP.NET Core Web API with default settings. -> Run once in release mode in docker. -> Close the container. -> Rerun the docker image via command line terminal using docker run -it -p 8080:8080 webapplication4:latest. -> The server is not accessible via https://localhost:8080/swagger.

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

Visual Studio 17.8.0 .NET 8.0.100

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 30 (16 by maintainers)

Most upvoted comments

@cropyai I can answer your questions about .NET MAUI and get you assistance with the issues impacting your development. So we don’t jam of this issue with the conversation, send me an email and we can connect once the conferences are done next week. david.ortinau@microsoft.com

Visual Studio does some extra work to pass in cert information when it runs your docker container. Let me see if I can find a sample command line.

@amcasey I was able to successfully run my backend server in a docker container on my local computer without any problem. For the ubuntu machine that we have, I tried to run the same image on that machine. However, it didn’t work at the beginning. I tried with a different machine and “somehow” it worked on the new machine even though both machines had the same security groups and settings. Now, we changed the machine to the new one on which the docker image worked well. Now, it seems there is no issue on my side. I don’t know why it didn’t work in the previous machine, but anyways. Thanks for the effort and helping me!

I guess this was a change from .NET 7 to .NET 8 or new docker images of aspnet, either way, we weren’t aware of the new behavior. Thank you again!

However, for .NET MAUI, it seems like developers can’t use the technology because of the bugs

I don’t work on MAUI myself, but I’ll see if I can put you in touch with someone. Thanks for the feedback!

Edit: the right people have been notified but there may be a delay because of multiple conferences this week and a major US holiday next week.

@amcasey Hi, it is not related to the port change, but a bug might be introduced while developing this change.

I started the docker with the correct parameters, however, it resulted in giving protocol error message. Again, to do a sanity check, I tried the commands on the webpage that you referred to. The result is the same!