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 https://www.microsoft.com/net/core#windows
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 https://www.docker.com/products/overview . 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 WORKDIR /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!