Container Tools in Visual Studio 2019

23 March 2020 at 13:07 by ParTech Media - Post a comment

Ever been irked by your inability to manage your applications effortlessly?
Ever felt frustrated seeing your application getting booted up slower than a tortoise?
Well, you are not alone. Thousands of developers face this issue on a daily basis.

So what is the solution? In one word: Containerization
Containerization is the process of virtualizing your operating system thereby making your application lightweight, quick to boot, secure and portable.
The best part: it is extremely easy to enable container tools in Microsoft Visual Studio 2019!

Want to know how? Read this post to understand more about containerization and the different ways to incorporate containerization in Microsoft Visual Studio 2019.

Table of Contents

  1. What is a container?
  2. Why do you need container tools?
  3. How to enable container tools in Microsoft Visual Studio?
  4. Tools to manage multiple containers in Microsoft Visual Studio

 

What is a container?

A container is a standard unit of application that encompasses all the necessary executable files and configuration files needed to run the application successfully.
Containers facilitate serverless architecture as they do not virtualize the hardware, rather they virtualize the operating system. The result - they tend to be extremely lightweight.
A popular platform to package an application inside a container is a Docker.

Often multiple containers forming a cluster might be required to deploy large applications.
In such scenarios, you need a container orchestrator to ensure that the containers are in perfect harmony to ensure their smooth running.
Tools like Kubernetes and Service Fabric make it possible to implement container orchestration in Microsoft Visual Studio 2019.

 

Why do you need Containerization?

Here are some of the reasons why you need to do containerization

  • Light Weight
    Using Container Tools makes your application extremely light and easy to boot since they avoid virtualizing the entire hardware stack.
    This effectively means they use fewer resources than what a traditional or virtual machine environment would require.
  • Portable Applications inside a container can be shuttled between different environments because they encapsulate all the necessary files to run the application into the container rendering them to be completely standalone.
  • Consistent operations Containerization ensures consistent operations in all the development and release cycles which ensures that your environment is standardized.
    Your DevOps team knows that your application will run the same irrespective of the location of deployment.
  • Isolation Containerization ensures that the applications and resources are separate since each container has its own resources to run an application. As a result, you can debug or modify an application without affecting another application.
  • Saves cost Since Containers don’t waste system resources owing to duplication of the operating system, more resources can be allocated to running the application which translates to fewer physical servers needed.
    Thus you can save costs by avoiding buying and maintaining multiple servers.

 

How to enable container tools in Microsoft Visual Studio 2019?

Now that we have seen the benefits of Containers, let us see how to enable container tools in Microsoft Visual Studio 2019 to reap its full benefits.
The tools included in Microsoft Visual Studio 2019 for developing with Dockers are available only for ASP.NET, ASP.NET Core, and .NET Core and .NET Framework console projects.
You can work with a docker either for a single project, or use tools like Docker Compose, Service Fabric, or Kubernetes to manage multiple services in containers.

Before you start containerization, ensure Docker Desktop is installed.
Next, to enable containerization for a single project, you need to add Docker Support in Microsoft Visual Studio 2019. The below screenshot specifies how to do it. Just select the checkbox of the ‘Enable Docker Support’ while creating a new project.

Have you already created a project? Fret not. You can still add docker support to it by navigating to Add > Docker Support as shown in the below screenshot.

Once you enable Docker support, Visual Studio automatically adds the following files into your project confirming the successful addition of docker into your project.

  • a Dockerfile file
  • a .dockerignore file
  • a NuGet package reference to the Microsoft.VisualStudio.Azure.Containers.Tools.Targets

 

Tools to manage multiple containers in Microsoft Visual Studio

With Visual Studio 2019, you can use Docker Compose, Kubernetes, and Service Fabric to manage multiple containers. Let us jump into details.

Docker Compose

Docker Compose is used to manage multiple containers when they are on the same host.
With a single command, you can start or stop the services in multiple containers from your configuration using Docker Compose.
To enable Docker Compose, right-click on the solution or project node in Solution Explorer, and then select Add > Container Orchestration Support. Then choose Docker Compose.

Kubernetes

Kubernetes is a container orchestration tool from the house of Google.
It differs from Docker Compose in its ability to manage containers running on multiple hosts thereby enabling scaling. It also helps in starting a new container when one crashes.
Through Kubernetes, you can connect the project in your local machine with a Kubernetes cluster that is running on Azure Kubernetes Service(AKS). This facilitates you to modify or debug your services in AKS with the help of Visual Studio.

To add Kubernetes support in Visual Studio, select Kubernetes/Helm while adding container orchestration support as in the screenshot below.

Service Fabric support

Service Fabric is an orchestration tool from Microsoft and like Kubernetes, it has the capability to manage containers on multiple hosts.
Service Fabric watches over the health of service throughout the application process. If a component of an application deployed by Service Fabric fails, it immediately rolls back the application to the previous version.

To add Service Fabric support in Visual Studio, here are the steps:

  • Enable Service Fabric Tools in Visual Studio Installer
  • Install Microsoft Service Fabric SDK and runtime using Web Platform Installer ( To install - Click here)
  • Create a Service Fabric Application while creating a new project

 

Conclusion

Containers are supremely crucial to ensure that your applications run butter smooth and at the same time are secure.
Microsoft Visual Studio 2019 makes your life easier by providing extensive support to enable containerization in your application in the form of Dockers.
And if you are managing a large application that is spread across multiple containers, then Visual Studio helps in manage it through tools like Kubernetes, Service Fabric and Docker Compose.

Latest