.Net on linux via docker!

It's never fun to install RC and Beta software, additionally software installs put bits everywhere and can be hard to clean up. If you're trying something for the first time and you're not afraid of Docker, it's a great option for trying things out without messing up the binary stability of your OS.

Since my write up on ASP.NET vNext a while back, they have changed the landscape a little.

First they have an installer page for all the major OS flavors AND the Docker link.

Microsoft .NET Core Install

If you go with the Docker container approach, there is nothing left to install, just run the below command

docker run -it microsoft/dotnet:latest

NOTE: Executing a docker container this way will generate a random name for it. After you exit you'll need to do docker ps -a and look for the last instance that ran your image. You can then re-use it by running docker start -i {name}

docker run -it --name dotnet microsoft/dotnet:latest 

you could then

docker start -i dotnet

Then you should see something to the effect of this


Hello World!

The old standby

Make a directory, change to it, and initialize a new project

mkdir -p src/helloworld && \
 pushd src/helloworld && \
 dotnet new

The directory should look something like this

root@2969ab87576c:/src/helloworld# ls -al
total 16
drwxr-xr-x 2 root root 4096 May 24 23:49 .
drwxr-xr-x 3 root root 4096 May 24 23:49 ..
-rwxr--r-- 1 root root  202 May 24 23:49 Program.cs
-rwxr--r-- 1 root root  285 May 24 23:49 project.json

Program.cs already has the Hellow World Console Echo in it already.
Project.json is what dotnet restore uses to download external dependencies and also defines the projects metadata for building.

Now that the files are there, you can restore the dependencies of the project by running

This takes some time depending on your connection and if you've done this already in your container

dotnet restore

After the wall of text fly's by and you have no errors
Fire off dotnet run

root@2969ab87576c:/src/helloworld# dotnet run
Project helloworld (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling helloworld for .NETCoreApp,Version=v1.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:03.2540075

Hello World!


The image comes with a CLI called dotnet

.NET Command Line Tools (1.0.0-preview1-002702)
Usage: dotnet [common-options] [command] [arguments]

  [command]     The command to execute
  [arguments]   Arguments to pass to the command

Common Options (passed before the command):
  -v|--verbose  Enable verbose output
  --version     Display .NET CLI Version Number
  --info        Display .NET CLI Info

Common Commands:
  new           Initialize a basic .NET project
  restore       Restore dependencies specified in the .NET project
  build         Builds a .NET project
  publish       Publishes a .NET project for deployment (including the runtime)
  run           Compiles and immediately executes a .NET project
  test          Runs unit tests using the test runner specified in the project
  pack          Creates a NuGet package

Initial File Contents

Contents of Program.cs

using System;

namespace ConsoleApplication
    public class Program
        public static void Main(string[] args)
            Console.WriteLine("Hello World!");

Contents of Project.json

  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"

Next Article we'll do something with ASP.NET