Getting started with ASP.NET Core and Docker

Here a post about getting started with .NET Core and Docker. Goal is to run a .NET webservice inside a Docker container.

Step 1] Get the stuff

a. Install .NET Core SDK

Get the .NET Core SDK at

There are installations for Windows, Mac and various Linux machines.

If installation goes well you should be able to run command ‘dotnet‘:


For fun try to run commands like ‘dotnet new‘, ‘dotnet restore‘ and ‘dotnet run‘ and a Hello World app should run:



b. Install Yeoman and ASP.NET generator

Yeoman is a command line tool for generating/scaffolding projects. Installation is easy: run ‘npm install -g yo’ (NodeJS should be installed).

After installation run the ‘yo’ command and install the aspnet generator:


c. Install Docker player

There are various methods to get Docker running on your machine, but most easiest is installing the Docker for Mac or Windows from . Warning: on Windows you need to have Windows 10 and Hyper-V enabled.

If installation goes well you can run the ‘Docker’ command:



Step 2: Create new application

Create a new application by running command ‘yo aspnet’ and choose ‘Web API Application’ option. Give the application a name and the application is created. Change the directory to the new application, run again ‘dotnet restore’ and ‘dotnet run’. Open a browser and navigate to ‘http://localhost:5000/api/values’‘ and the response should be: [“value1″,”value2”]




Step 3: Run from Docker

Now it’s time to run the application from Docker. The ASP.NET generator has also created a sample Dockerfile:

FROM microsoft/dotnet:latest

COPY . /app


RUN ["dotnet", "restore"]

RUN ["dotnet", "build"]

EXPOSE 5000/tcp

CMD ["dotnet", "run", "--server.urls", "http://*:5000"]

Run from the command line the following commands:

$ docker build -t mydemos:aspnetcorehelloworld .


A new Docker image is created containing our new application. Now start a new container by the following command:

$ docker run -d -p 8080:5000 -t mydemos:aspnetcorehelloworld


The container is started and should be available at port 8080:


Voila, we have a new ASP.NET Core application running from Docker!


6 thoughts on “Getting started with ASP.NET Core and Docker

  1. Hello!
    I’m not familiar with docker and so I’m trying to succeed with your tutorial.
    When executing -> docker build -t mydemos… with the sample dockerfile it will stopp at step 4/7 saying that the specified sdk version 1.0.0-rc4-004771 not found! I actually have installed exactly this version of dotnet core sdk.

    any hints?

      • Hi, I made it work. Had to edit the global.json file.
        Now I struggle with the next step. I would like to build a docker image for cesium terrain builder. I found the content for the dockerfile but it won’t let me set up this image -> connection refused! Do I need to create first a new web api application?
        I’m actually quiet a beginner working with docker. My goal is to create a cesium viewer with own terrestrial data, ortho images, 3d-buildings and point clouds… I first start with TIFF files with height information.
        If you maybe have more information about it or maybe you know where to find the desired informations in the web?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s