好的,我创建了空的 RC2 项目并使用 VS 2015 在本地运行,它可以工作。
现在我想使用 docker 将其部署到 Linux 服务器 - 那么我的 dockerfile 应该是什么样子?我一直在关注these instructions ,这就是我最终得到的结果:
FROM microsoft/dotnet:1.0.0-preview1
COPY . /app
WORKDIR /app
RUN dotnet restore
EXPOSE 5004
ENTRYPOINT dotnet run
然后我将我的应用程序构建为图像: docker build -t my_app 。
并使用以下命令运行: docker run -t -p 8080:5004 my_app
之后我得到了图像正在运行并且正在 localhost:5000 上监听的信息。不幸的是,我一直在尝试使用 xxxx:5000、xxxx:5004 和 xxxx:8080 连接到该服务器,但这些地址都不起作用(xxxx 是服务器地址)。
我做错了什么吗?
最佳答案
您还可以在 Dockerfile 级别指定 URL(如果您想重用容器则更好)。这是完整的 Dockerfile:
FROM microsoft/dotnet
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "run", "--server.urls=http://0.0.0.0:5000"]
您还需要修改 Program.cs 文件以从主参数读取配置:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
您可以在这篇博文中找到分步教程及其原因: https://www.sesispla.net/blog/language/en/2016/05/running-asp-net-core-1-0-rc2-in-docker/
关于docker - 在定义的端口上运行 RC2 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37394917/