我有一个在 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/