我有一个基本的Web api(owin self host)应用程序,它在我的本地docker工具箱(windows)中运行良好。
但是当我使用 docker 云启动它时,它会启动,但在 5 或 6 秒后它停止了。 我不知道该怎么办。我正在使用mono:最新图像和我的云托管环境。是数字海洋。
这是代码
课程.cs:
string address = "http://+:5000";
using (WebApp.Start<Startup>(address))
{
Console.WriteLine("web api listening on port 5000");
Console.Read();
}
只是这个。
启动.cs
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
app.UseWebApi(config);
Dockerfile :
from mono:latest
run mkdir app
copy ./GAC/bin/Debug /app
workdir /app
expose 5000
entrypoint ["mono"]
cmd ["GAC.exe"] // gac is the console app name.
就是这样。我通过键入 docker run -it -p 80:5000 myContainer
来运行我的容器。而且它运行没有停止问题。我在Windows中构建了我的容器,所以也许我遇到了一些基于Unix的问题。
你觉得怎么样?有什么遗漏点吗?
我找到了答案。我不知道为什么,但问题是代码根本不等待。
上面的代码正在工作。
string address = "http://+:5000";
using (WebApp.Start<Startup>(address))
{
Console.WriteLine("web api listening on port 5000");
while(true){}
}
我假设你也有一个 API 控制器?另外,你在推动什么到码头工人云?我假设它是一个图像而不是一个容器?谢谢。