Lead Developer Peter Duerden – who is currently working on Control F1’s Innovate UK-funded “i-Motors” telematics project – gives his top tips on how to best utilise Docker’s containerised solution for .NET development.
The recent rise in popularity of the Micro-Services Architecture has resulted in a shift in the way architects and developers design and develop their solutions. This architecture allows developers to build software applications which use independently deployable software components.
To assist in the paradigm of the Micro-Services Architecture, Solomon Hykes released an open source project called Docker in March 2013. Docker provides a lightweight containerised solution that builds upon the Linux kernel’s ability to use namespaces, but – unlike a virtual machine – a Docker container works with resource isolation using namespaces.
From the background above, you would think that the ability to utilise Docker for .NET development would be limited. However, Microsoft has invested time in Docker Tools for Visual Studio 2015 – Preview. This adds support for the building, deploying and debugging of containers using Mono and, more recently, .NET Core, which can be deployed or debugged locally when used in conjunction with Docker Toolbox or Docker for Windows (or Mac).
The Docker Tools have changed quite dramatically from their early releases, and during conversations with the development team in Seattle I was able to request, amongst other things, the inclusion of .NET Console apps to receive support for deployment. That request has been included into the current toolset.
The Docker Tools are a real benefit for fast development, but understanding the Docker processes before using them can help, and actually manually writing a Dockerfile for building your own images can prove valuable if you are to reap the full benefits of what Docker can offer.
Docker containers can be hosted on any Linux machine running the Docker daemon, but you need more than one in a production environment, and will need to run a Docker Swarm that can manage the allocation of containers, resourced over multiple machines to ensure resilience should one machine fail.
NB certain Cloud providers offer their own “Container Services” which ease the deployment of containers, but don’t use the standard Docker tools for composing or scaling.
Although you may want to just dive in and try your first Docker container, be mindful of the following:
- Understand the Docker build process
- What is it doing when it builds the images using the Dockerfile?
- How are things layered?
- Exposing ports – make sure you think about why and when
- Have you considered tagging?
- Experiment with Docker Compose
- Build your application by linking services
- “Internal” services do not need ports exposing to the Host machine
- Build your own Docker Swarm
- By building a swarm you can understand and identify the related challenges this will have, such as service registry or load balancing
- Use Docker natively. Don’t use one hosting provider’s container service, as this will tie you in and mean further work to unstitch your solution if you ever decide to host elsewhere.
- Be aware that not all .NET Nuget packages support .NET Core. There are certain ones that do, but quite a few still aren’t supported.
At the time of writing this, quite a few changes are occurring in both the Docker and .NET Core spaces, which will no doubt have an impact on future development.
- .NET Core has now been released. Hopefully this will drive an increase in the number of Nuget packages available to developers.
- Docker Swarm has been simplified and should hopefully make it easier to build and manage swarms.
- Microsoft are close to the release of Windows Container Service, which offers similar functionality to Docker, but on Windows Server 2016. This will therefore allow for full .NET framework capabilities rather than the .NET Core version.