c# - 无法访问通过 docker 在 Postman 的 80 端口上运行的 API

标签 c# docker docker-compose dockerfile

我有一个在 Docker 中运行的简单 API
当我运行命令来运行我的图像时,我得到下面的输出

docker run newapi:latest mee
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:80
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: /api
这一切看起来都很好
但是,使用 Postman 时连接被拒绝
http://localhost/天气预报
知道有什么问题吗?
我的 docker 文件是:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /api

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

EXPOSE 80

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /api
COPY --from=build-env /api/out .
ENTRYPOINT ["dotnet", "api.dll"]
如您所见,我正在暴露端口 80
我可以使用 http://localhost:8080 但我只想能够使用 http://localhost

最佳答案

当您运行 docker 尝试映射端口

docker run -p 80:80 newapi:latest mee

关于c# - 无法访问通过 docker 在 Postman 的 80 端口上运行的 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64170879/

相关文章:

docker - kubernetes如何检测docker守护进程

mysql - Derby 安 : Using a cron task on Docker

docker - 为什么安装了 Docker 而不是 Docker Compose?

linux - 检查 docker-compose 服务是否正在运行

c# - 在 switch 语句中使用对象的 string.contains 方法?

C# Volley 如何获取 OnResponse?

WSL2 中的 Docker : Cannot connect to the Docker daemon at tcp://localhost:2375. docker 守护进程是否正在运行?

c# - sql 2012 express 和 vs2012

c# - 使用字符和数字对 List<> 进行排序

Docker:如何从给定容器访问另一个容器中的文件?