dotnet 核心 docker web api 未连接

问题描述

我正在努力让我的 docker 容器在 localhost 上监听(一直无法访问站点)。我遵循了有关 jetbrains 的官方指南以及我在网上找到的其他一些指南,但仍然没有运气。

在我的本地开发中,我希望我的 Web API 容器和 Postgres 容器相互通信,但在运行时容器将与 en RDS 实例通信

Docker 文件

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
workdir /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080

# copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
workdir /src
copY . .
RUN dotnet restore "api/api.csproj"
workdir "/src/api"
RUN dotnet build "api.csproj" -c Release -o /app

FROM build AS publish
workdir "/src/api"
RUN dotnet publish "api.csproj" -c Release -o /app

FROM base AS final
workdir /app
copY --from=publish /app .
ENTRYPOINT ["dotnet","api.dll","--urls","http://*:8080"]

启动设置

  "$schema": "http://json.schemastore.org/launchsettings.json","iisSettings": {
    "windowsAuthentication": false,"anonymousAuthentication": true,"iisExpress": {
      "applicationUrl": "http://localhost:14317","sslPort": 44301
    }
  },"profiles": {
    "IIS Express": {
      "commandName": "IISExpress","launchbrowser": true,"launchUrl": "","environmentvariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },"wander.api": {
      "commandName": "Project","applicationUrl": "https://localhost:8081;http://localhost:8080","environmentvariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

我的 Docker 调试配置

My Docker debug config

我的码头工人 PS

enter image description here

解决方法

请分享您的 docker run 命令。我确定您指定了 -p 选项。

我猜它看起来像下面:

docker run <cotainer id> -p 57000:8080

8080 将在 docker 容器网络中使用。

从主机,您可以使用 57000 访问 API。