Now that we understand the concept behind containers, lets install Docker for Windows and run our first sample .NET Core container.
- 64bit Windows 10 Pro, Enterprise and Education (Anniversary Update or later)
- Virtualization must be enabled in BIOS and CPU SLAT-capable
- Microsoft Hyper-V to run. The Docker for Windows installer enables Hyper-V for you, if needed, and restart your machine
Download and install
Follow the wizard to install and then run Docker for Windows to start. It typically takes a few minutes in first start because it’s creating a new VM and virtual switch on Hyper-V.
By default Linux containers are enabled. You can’t run both Windows containers and Linux containers on a single machine. I recommend that you keep Linux containers as most of the containers comes in Linux by default, even Microsoft .NET Core ones. But if you need to, you can switch by right clicking the Docker icon in the notification area and choose “Switch to Windows containers…”
Run your first dotnet sample container
Now open a command line window and the following to explore docker commands:
docker pull microsoft/dotnet-samples:aspnetapp
This will download a container image from Docker Hub. The first part is a registry named “microsoft/dotnet-samples” that has multiple images (different versions, flavors, samples). The second part “:aspnetapp” is called a tag, which identify specific image to pull.
The image we chose above has the following:
- Linux Debian Stretch (a distribution of linux that serve as a compact base for the container)
- .NET Core runtime
- ASP.NET Core host that runs on port 80
- A sample web application
Now lets run this image:
docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp
This command tells docker to:
- Create and run a container from our downloaded image
- Give it a name aspnetcore_sample ( — name)
- Forward port 8000 on your localhost to port 80 inside the container (-p)
- Remove the container if it was already running ( — rm)
- Show shell output from container in this console (-it)
Now browse http://localhost:8000/ you will see the sample website running :)
On another command window try the following commands to recap:
List all downloaded images:
List currently running containers:
How to explore other images
Now that you have downloaded and run your first container, lets look at what other images available on Docker Hub.
This is where we got our sample image: https://hub.docker.com/r/microsoft/dotnet-samples/
This is the official images for dotnet core: https://hub.docker.com/r/microsoft/dotnet/
with recommended tags:
microsoft/dotnet:2.1-aspnetcore-runtime for only hosting a web app
microsoft/dotnet:2.1-sdk for building apps with dotnet commands
This is the list of popular other images: https://hub.docker.com/explore/
Right click the Docker notification icon and choose “Kitematic”. This will open a GUI window that will let you do few things on docker.