我正在嘗試使用ASP.Net Core和Docker設置開發環境。圖像正確構建,容器運行正常。但是,即使我已指定端口爲主機和容器的5000端口,但dotnet仍會在不包含指定端口的url上啓動服務器,也不可訪問。我期待聽衆是在:http://localhost:5000
DockNet容器中的「dotnet run」導致無法訪問url
docker-compose up
結果:
Recreating netcore_ms1_1 ...
Recreating netcore_ms1_1 ... done
Attaching to netcore_ms1_1
ms1_1 | Hosting environment: Production
ms1_1 | Content root path: /app
ms1_1 | Now listening on: http://[::]:80
ms1_1 | Application started. Press Ctrl+C to shut down.
我的應用程序僅僅是一個樣品dotnet new web
應用模板。這裏是我的Dockerfile和碼頭工人,compose.yml文件:
Dockerfile
FROM microsoft/aspnetcore-build:2.0.0-jessie
WORKDIR /app
EXPOSE 5000
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]
泊塢窗,compose.yml
version: '3'
services:
ms1:
build: ./ms1
ports:
- "5000:5000"
volumes:
- ./ms1:/app:Z
有人能指出我我缺少什麼?
其他問題
如何,我會繼續在泊塢窗容器中運行的DOTNET看守工具,更具體地運行dotnet watch run
,留意是否有安裝的卷./ms1文件的變化?
在此先感謝,任何幫助,非常感謝。
好像它偵聽80,但你要在'搬運工,compose.yml'訪問5000最簡單的解決方案可能僅僅有5000重定向到80。 – kichik
我試着改變docker-compose.yml中的端口,但結果是一樣的。 –
端口改變了如果你從控制檯執行'dotnet run --server.urls'http://0.0.0.0:5000''' '--server.urls'只有在顯式啓用從args中讀取配置(當設置WebHost時)時才起作用。你添加了'.AddCommandLine(args)'?看看[WebHostBuilder。如何使用.NET-Core 2.0中的CommandLine設置URL地址](https://stackoverflow.com/questions/45710570/webhostbuilder-how-to-set-url-address-using-commandline-in-net-core-2 -0/45712524#45712524)如果需要樣品。 – Set