[英]Connecting to Docker Container .Net Core
因此,我正在嘗試對.NET Core項目進行Docker化。 我能夠創建映像並運行容器,但是即使暴露了端口,我也無法連接到容器。 我使用以下命令運行容器:
docker run -d -p 8080:80 --name myapp aspnetapp
當我運行並檢查日志時,將顯示以下內容:
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.
這是我的Program.cs
var host = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
這是我的DockerFile:
FROM microsoft/aspnetcore-build:1.1.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY ./*.sln ./
RUN dotnet restore nde-configuration-editor.sln
# Copy everything else and build
COPY . ./
RUN dotnet restore ./nde-configuration-editor
RUN dotnet restore ./AspNetCore.Identity.InMemory
RUN dotnet publish nde-configuration-editor.sln -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:1.1
WORKDIR /app
COPY --from=build-env /app/nde-configuration-editor/out .
ENTRYPOINT ["dotnet", "nde-configuration-editor.dll"]
我嘗試使用http:// localhost:8080從瀏覽器進行連接,但無法訪問該站點。
我缺少什么?如何連接到容器?有幫助嗎?
謝謝
添加“ ASPNETCORE_URLS http://0.0.0.0:80 ”環境變量。
或直接在此處更改(在.net core RC2之前)在Web應用根目錄的project.json中。
"commands": {
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:80"
},
對於.netcore RC2
create file hosting.json in web-app root and add
{
"server.urls": "http://0.0.0.0:80"
}
並且它需要更改代碼。
其他最簡單的方法是
dotnet run --server.urls "http://0.0.0.0:80"
這里記錄了它的https://andrewlock.net/configuring-urls-with-kestrel-iis-and-iis-express-with-asp-net-core/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.