所以我试图将.NET核心项目停靠 . 我能够创建图像并运行容器,但即使我暴露了端口,我也无法连接到容器 . 我用这个命令来运行容器:
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从浏览器连接它无法访问网站 .
我缺少什么?我如何连接到容器?任何帮助?
谢谢
1 回答
添加“ASPNETCORE_URLS http://0.0.0.0:80”环境变量 .
或者在web-app root的project.json中直接更改(在.net core RC2之前) .
对于.netcore RC2
它需要更改代码 .
最简单的方法就是运行
这里记载了https://andrewlock.net/configuring-urls-with-kestrel-iis-and-iis-express-with-asp-net-core/