连接到Docker Container .Net Core
所以我试图dockerize一个.NET核心项目。 我能够创build图像并运行容器,但是我无法连接到容器,即使我暴露了端口。 我用这个命令来运行容器:
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从浏览器连接,它使网站无法访问。
我缺less什么?我如何连接到容器?任何帮助?
谢谢
添加“ASPNETCORE_URLS http://0.0.0.0:80 ”环境variables。
或者在web-app root的project.json中直接更改(在.net core RC2之前)。
"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"
在这里它logging的https://andrewlock.net/configuring-urls-with-kestrel-iis-and-iis-express-with-asp-net-core/