【发布时间】:2017-01-18 11:09:12
【问题描述】:
我正在尝试使用 Docker 将最低限度的测试 .NET Core Web API 部署到 Elastic Beanstalk,但没有任何成功。
源代码
我在 Visual Studio 中创建了一个全新的 .NET Core Web API 项目,并且没有修改生成的示例代码。之后我在项目的根目录中添加了Dockerfile,内容如下:
FROM microsoft/dotnet:onbuild
EXPOSE 5000
For your curiosity, here's a link to the .NET docker repo.
之后,我在项目的根目录中创建了一个hosting.json 文件。我想将 Kestrel 服务器绑定到容器的所有 IP。 hosting.json 文件有以下内容:
{
"urls": "http://*:5000"
}
为确保应用正在加载该配置文件,我将 Main 方法更改为:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: false)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseConfiguration(config)
.Build();
host.Run();
}
If needed, here's the documentation on the hosting.json file.
最后,即使我不需要它according to AWS documentation,我在项目的根目录中创建了一个Dockerrun.aws.json,其内容如下:
{
"AWSEBDockerrunVersion": "1"
}
这一切在我的本地机器上运行得很好。我使用以下命令运行它:
docker build -t netcore .
docker run --rm -itp 5000:5000 netcore
我已通过在浏览器中访问 url http://localhost:5000/api/values 来验证它是否有效。它产生了预期的结果!
AWS
现在为了将其部署到 Elastic Beanstalk,我已将整个源代码与 Dockerfile 和 Dockerrun.aws.json 一起存档。 ZIP 文件中的根目录如下所示:
Controllers/
Properties/
wwwroot/
appsettings.json
Dockerfile
Dockerrun.aws.json
hosting.json
Program.cs
project.json
project.json.lock
Startup.cs
web.config
但是,将这个源包部署到 Elastic Beanstalk,使用单个 Docker 容器单实例环境,会产生以下错误 No Docker image specified in either Dockerfile or Dockerrun.aws.json. Abort deployment.
我做错了什么?我该如何让它发挥作用?
【问题讨论】:
-
几个小时后,我仍然无法让它工作。我确信我所做的事情有问题,但有一件事是肯定的;错误消息完全不正确。显然指定了一个 Docker 映像......现在,如果只有消息可以指示实际错误。
标签: windows amazon-web-services docker amazon-elastic-beanstalk .net-core