[英]Cannot hit Dockerized .net core application using localhost and port
我有来自 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/
启动设置.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"
}
}
}
文件
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
version: '3.0'
services:
api:
ports:
- "8080:5000"
- "8081:5001"
build:
context: .
dockerfile: MyApp.API/Dockerfile
image: myapp/api:runtime
您是否有理由为 http(s) 请求使用端口 5000 和 5001 而不是 80 和 443? 如果你使用的是 Visual Studio,它会为你生成一个默认公开端口 80 和 443 的 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.