First use of Docker with ASP.Net Core
Now I have Docker up and running I wanted to set up an ASP.Net Core application. As with Docker itself, getting a simple “Hello, World” application running in the corporate environment was not as straightforward as I could have hoped. Below is the summary of the steps I had to take which will hopefully save other people some considerable time! I have pushed the source code up to my git repository and have made each incremental change a distinct commit so it is easy to follow.
Hello, world
First I started off with a very basic ASP.Net Core app by creating a new project in Visual Studio and accepting all the defaults. I didn’t add Docker support since I want to incrementally add it rather than jumping straight in with Docker Compose etc. My initial commit shows the basic app which can be run and tested via standard dotnet:
Browse to http://localhost:53545/api/values
Dockerfile
In order to build a Docker image in a repeatable, automated way, we can use a Dockerfile. This is a simple text document which starts with a base image (like a basic Ubuntu install or Windows Nanoserver) followed by a list of command-line instructions that assemble your image. A simple Dockerfile would look something like this one, a mix of two dotnet sample Dockerfiles for basic dotnet and aspnet:
The Dockerfile is pretty self-explanatory (although see this post for more on the dotnet base docker images). I haven’t yet worked out why the nuget restore and source code copy are separate steps, though.
Building my application from the Docker command line runs this Dockerfile and gives me this output:
I don’t have access to nuget.org through the corporate firewall. Next I’ll look at how to resolve this problem, and get my first Docker app up and running.
docker (9) netcoreapp (10)