skip to Main Content

I’m trying to dockerize a dotnet 8 web api project.
I’m on Windows 10 with Docker Desktop installed.

This is the Dockerfile I’m using

FROM mcr.microsoft.com/dotnet/aspnet:8.0 

WORKDIR /app

# Copy the built application from the build image
COPY ./bin/Release/net8.0/ /app

# Expose the port the app will run on
EXPOSE 5000

# Set the environment variable for ASP.NET Core
ENV ASPNETCORE_URLS=http://+:5000

# Set the entry point for the application
ENTRYPOINT ["dotnet", "Finch.Agents.dll"]

This is the launchSettings.json:

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:60197",
      "sslPort": 44302
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7120;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

And this the docker-compose.yml part with which I run the container

  finch-agent:
    image: finch-agent:1.0.0
    container_name: finch-agent
    ports:
      - "8081:5000"

Below is the docker logs ...

---------------------------------------------
.... my logs ...
---------------------------------------------
warn: Microsoft.AspNetCore.Hosting.Diagnostics[15]
      Overriding HTTP_PORTS '8080' and HTTPS_PORTS ''. Binding to values defined by URLS instead 'http://+:5000'.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /app

between the ----- lines appears some custom log messages I printed, so I’m sure the application is running.
Besides, it seems that the application is correctly listening on port 80.

Why, then, if I open the browser at http://localhost:8081/swagger I get a 404 ERROR? (I also get the same error at http://localhost:8081/)

PS: ‘m also sure that the application works correcly when running with dotnet run, not dockerized.

edit:

additional information: Following thepip3r comments, I add the following information:

results of netstat -anop

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer
tcp        0      0 127.0.0.11:35509        0.0.0.0:*               LISTEN      -                    off (0.00/0/0)
tcp6       0      0 :::5000                 :::*                    LISTEN      1/dotnet             off (0.00/0/0)
udp        0      0 127.0.0.11:38653        0.0.0.0:*                           -                    off (0.00/0/0)
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     STREAM     LISTENING     47244    1/dotnet             /tmp/dotnet-diagnostic-1-156353-socket

Concerning general and security settings for Docker Desktop, I can add that other containers exposing web apps (not dotnet, eg. I’ve got a phpmyadmin container running witht he same docker-compsoe), work correctly.

2

Answers


  1. In .NET 8.0 Microsoft has changed Dockerfile which now use 8080 and 8081 ports. So you must use these port for accessing your ASP.NET Core app on Docker container. This working example – Multi-Container ASP.NET Core App with Docker Compose is based on .NET 8.0 version and will help you to make changes.

    Login or Signup to reply.
  2. You could add the following line into the Dockerfile

    ENV ASPNETCORE_HTTP_PORTS 80

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search