.NET Core Quickstart Docker

.NET Core Apps in Containers in Windows 2016 Quickstart Guide

Containers on Windows Server 2016 is one of the newest features on Microsoft’s Server Operating System. Among many other new features, containers offer a way to run application in an isolated environment that is also highly automated for builds and deployments with the new .NET Core command line utilities and the integration that Docker has with Windows Server 2016 and containers. This tutorial walks through the steps on how to go from zero to containerized app in no time.

On Server 2016

  1. Assuming Server is installed, run a PowerShell terminal. Either launch it from the Start Menu, or if you’re running without the GUI, just type in “powershell”.
  2. Add the repositories for Docker to the server
     Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
  3. Install the Container Engine and Docker on the server
     Install-Package -Name docker -ProviderName DockerMsftProvider

    NOTE: – if you get an error about needing to install updates or hotfixes, you can use sconfig from the CLI to install these. Simply type in sconfig and select option 6. After the updates run, try installing the continer engine again.

  4. Reboot the Server.
     Restart-Computer -Force
  5. Test Docker. Run a simple Docker command to make sure it is installed and working without any errors.
     docker ps -a

Create a Project

Note: These steps in this section can be performed on a Windows Dev Box or the Server itself. If you’re just going through this, you can run these on the server.

  1. Download Node.JS. Node’s package manager (npm) is needed to install some of the dependencies that are used by the .NET command line.
     Invoke-WebRequest -Uri https://nodejs.org/dist/v6.9.2/node-v6.9.2-x64.msi -OutFile node.msi
  2. Install Node.JS. Node’s package manager (npm) is needed to install some of the dependencies that are used by the .NET command line.
     msiexec -i node.msi /quiet
  3. Download and install .NET Core SDK.
     Invoke-WebRequest -Uri https://go.microsoft.com/fwlink/?LinkID=835014 -OutFile DotNetCore.exe
  4. Install .NET Core.
     ./dotnetcore /quiet
  5. Allow about 5 minutes for the node and .NET installers to finish.
  6. Reboot.
     Restart-Computer -Force
  7. Restart the powershell terminal and install Gulp and Bower. These are used when publishing .NET apps.
     npm install -g gulp
     npm install -g bower
  8. Create a project folder.
     mkdir my-project
  9. CD to the project folder.
     cd my-project
  10. Create a new .NET web project.
     dotnet new -t Web
  11. Install all of the dependencies and libaries. Once the restore is done, you can develop on the project and the like. For this tutorial, it isn’t necessary to do anything, but this is the point were you would do develop your application.
     dotnet restore
  12. Publish the application. This will create a publish folder. Look at the output for the folder path. It’s usually under the app folder in bin\Debug\netcoreapp1.1\publish
     dotnet publish
  13. Change directories to the published folder.
     cd bin\Debug\netcoreapp1.1\publish
  14. Create a Dockerfile. Note, this image is using a version of .NET that matches the output of the publish, which happens to match the version of the .NET SDK that was installed earlier.
     echo @"
     FROM microsoft/dotnet:1.1.0-runtime-nanoserver
     ENTRYPOINT ["dotnet", "my-project.dll"]
     ENV ASPNETCORE_URLS http://+:80
     EXPOSE 80
     COPY . .
     "@ | Set-Content -Encoding utf8 Dockerfile

On Server 2016

  1. If the files were created on a Dev box other than the server, move the publish folder to the server and CD to that folder. Depending on the level of trust on the network or the location of the server….
  2. Create a Docker image.
     docker build --tag my-project --no-cache .
  3. Run the Docker image.
     docker run -dit --name my-project -p 80:80 my-project
  4. Your application is now running inside of a container on Windows! You can get IP address for the computer by typing in:
     ipconfig -a

    Look for the containers IP address. This IP is what can be used to access the web site running inside of the container. Luanch a browser and browse to http://[your-server-ip-address].

It’s a little long winded, with a little time and effort, you can be up and running with .NET core apps inside of Windows Containers in no time!

1 comment on “.NET Core Apps in Containers in Windows 2016 Quickstart GuideAdd yours →

Leave a Reply

Your email address will not be published. Required fields are marked *

19 − 11 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.