简体   繁体   English

无法使用本地主机和端口访问 Dockerized .net 核心应用程序

[英]Cannot hit Dockerized .net core application using localhost and port

I have .net core 3.1 dockerized and up ( docker-compose up --build ) from docker container but I still cannot reach any swagger url from the application using http://localhost:8080/ or http://127.0.0.1:8080/我有来自 docker 容器的 .net core 3.1 dockerized 和 up ( docker docker-compose up --build ),但我仍然无法使用http://localhost:8080/http://127.0.0.1:8080/从应用程序访问任何 swagger url http://127.0.0.1:8080/

launchSettings.json启动设置.json

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
    "MyApp.API": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://0.0.0.0:5001;http://0.0.0.0:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
}

Dockerfile文件

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
WORKDIR /home/app 
Copy ... projedct files ommited on purpose for clarity ...
RUN dotnet restore 
COPY . . 
RUN dotnet publish MyApp.API/MyApp.API.csproj -o /publish/ 
WORKDIR /publish 
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
ENTRYPOINT ["dotnet", "MyApp.API.dll"]

docker-compose.yml docker-compose.yml

version: '3.0' 
services:  
  api:
    ports: 
      - "8080:5000"
      - "8081:5001"       
    build:
      context: .      
      dockerfile: MyApp.API/Dockerfile
    image: myapp/api:runtime   

Is there a reason you are using port 5000 and 5001 instead of 80 and 443 for your http(s) requests?您是否有理由为 http(s) 请求使用端口 5000 和 5001 而不是 80 和 443? If you're using Visual Studio, it will generate a Dockerfile for you that exposes port 80 and 443 by default.如果你使用的是 Visual Studio,它会为你生成一个默认公开端口 80 和 443 的 Dockerfile。 If you really want to use 5000 and 5001, you can expose those in your Dockerfile.如果你真的想使用 5000 和 5001,你可以在你的 Dockerfile 中公开它们。

FROM mcr.microsoft.com/dotnet/core/sdk:3.1
WORKDIR /home/app 
EXPOSE 5000
EXPOSE 5001
Copy ... projedct files ommited on purpose for clarity ...
RUN dotnet restore 
COPY . . 
RUN dotnet publish MyApp.API/MyApp.API.csproj -o /publish/ 
WORKDIR /publish 
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
ENTRYPOINT ["dotnet", "MyApp.API.dll"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在自定义端口上打开dockerized .net核心api - Cannot open dockerized .net core api on custom port 无法从 dockerized.Net Core 应用程序使用 Kafka - Cannot consume Kafka from a dockerized .Net Core application dockerized django 应用程序无法连接到本地主机上的 mysql 服务器 - dockerized django application cannot connect to mysql server on localhost 无法使用 dockerized 应用程序访问本地主机 - Cannot access localhost with dockerized app 无法从 dockerized ASP.NET Core 3.1 容器查询 dockerized MongoDB 容器 - Cannot query dockerized MongoDB container from dockerized ASP.NET Core 3.1 container 使用JetBrains Rider调试dotnet核心dockerized应用程序 - Debugging dotnet core dockerized application using JetBrains Rider dockerized net core 5 api的问题 - problems with dockerized net core 5 api 无法将 dockerized springboot 应用程序连接到非 dockerized postgres 数据库(本地主机) - Cant connect dockerized springboot application to not dockerized postgres database (localhost) .Net 核心 3.1 webapi dockerized,连接到数据库 MySql 时出错(没有 dockerized) - .Net core 3.1 webapi dockerized, error in connection to database MySql (No dockerized) 如何连接 Dockerized ASP.NET Core app -> Dockerized PostgreSQL? - How to connect Dockerized ASP.NET Core app ->Dockerized PostgreSQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM