Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a .NET Core Web API using Docker on Elastic Beanstalk

I am trying to deploy a bare minimum testing .NET Core Web API using Docker to Elastic Beanstalk without any success.


The source code

I've created a brand new .NET Core Web API project in Visual Studio and left the generated example code untouched. After that I added a Dockerfile to the root of the project with the following contents:

FROM microsoft/dotnet:onbuild

EXPOSE 5000

For your curiosity, here's a link to the .NET docker repo.

After that I created a hosting.json file in the root of the project. I wanted to bind the Kestrel server to all IPs of the container. The hosting.json file has the following contents:

{
    "urls": "http://*:5000"
}

To make sure the app is loading that configuration file I changed my Main method to this:

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.

Lastly, even though I do not need it according to AWS documentation I created a Dockerrun.aws.json in the root of the project with the following contents:

{
    "AWSEBDockerrunVersion": "1"
}

All this runs just fine on my local machine. I've run it using the following commands:

docker build -t netcore .
docker run --rm -itp 5000:5000 netcore

I've verified that it works by visiting the url http://localhost:5000/api/values in my browser. It produces the expected results!


AWS

Now in order to deploy it to Elastic Beanstalk I've archived the entire source code togheter with the Dockerfile and Dockerrun.aws.json. The root within the ZIP file looks like this:

Controllers/
Properties/
wwwroot/
appsettings.json
Dockerfile
Dockerrun.aws.json
hosting.json
Program.cs
project.json
project.json.lock
Startup.cs
web.config

However, deploying this source bundle to Elastic Beanstalk, using a single Docker container single instance environment, produces the following error No Docker image specified in either Dockerfile or Dockerrun.aws.json. Abort deployment.


What am I doing wrong? How do I get this to work?

like image 638
Niklas Ekman Avatar asked Sep 10 '16 12:09

Niklas Ekman


People also ask

Can Elastic Beanstalk deploy Docker?

This platform branch offers both single-container and multi-container support. Elastic Beanstalk deploys a Docker image and source code to EC2 instances on this platform branch. Use the Docker Compose tool on the Docker platform to simplify your application configuration, testing, and deployment.


1 Answers

So this was all developed on a Windows machine, i.e. Windows line endings, and it seems that Elastic Beanstalk does not detect that. That explains why Elastic Beanstalk could not parse a FROM <image> out of my Dockerfile since there's unwanted gibberish, hence the error message No Docker image specified....

I hope this gets noticed and fixed!

In the meantime I am using the Visual Studio plugin Line Endings Unifier which enables me to right click on the file and change the line endings to whatever kind I want.

like image 149
Niklas Ekman Avatar answered Sep 24 '22 08:09

Niklas Ekman