Skip to main content

Containers and Docker





Containers and Docker


  • Docker is an app (open source, Docker Inc is a company).
  • Docker and Containers are not the same, Docker provides a more usable way to manage Containers, without Docker it is very difficult but it can be done.
  • Docker is not the only Container management software but it is the most popular.
  • Docker reads Docker files. The Docker files contain instructions on how to run Containers.
  • An Image is the signature of the Container, the Container is the instance/running image.
  • Containers are applications. These applications need somewhere to run, they run in an Operating System provided by the Cloud of your choice e.g. Azure or AWS.
  • Containers can contain any applications and Containers can run other Containers. You can build up complex Containers using other Containers.
  • Containers are lightweight and start up very fast, quicker than VMs as they do not have their own OS.
  • DockerHub is a store where you can get other Containers.
  • Docker Containers are Stateful i.e. the can be shutdown and restarted and will still have the data. This also means that Databases can be ran inside Docker Containers.

Resources

Containers

Containers do not have their own Operating System, this makes them lighter than a Virtual Machine
Windows Containers are slightly slower and more complicated than Linux containers, because the Windows Container requires additional Processes to run, which Linux does not.

Image vs Container

A Container can be made up of many Images, stacked one on top of the other. These do not persist data by default, meaning that no matter how many times you create a Container from an Image it will always be the same Container. However if you wish to persist data to the a new Image then you can use the docker commit command, this creates a new Image with your data, the data resides in a Layer on top of the others.

.NET Containers

Use .NET Core instead of .NET Framework for Containers. .NET Core does not have UI's either Windows or WebForms, it does support a command line. 
ASP.NET MVC apps can be, apparently,  converted to Docker Images and then Docker Container,  https://docs.microsoft.com/en-us/aspnet/mvc/overview/deployment/docker-aspnetmvc
Windows Services to Docker Containers with .NET Core https://stackify.com/creating-net-core-windows-services/

Converting .NET applications to a Docker Container

.NETStandard .NET Core or .NET Framework

  • .NET Core made .NET available on other OSs. 
  • .NET Core still does not cover all that was in .NET Framework. 
  • .NETStandard is the real bare bones .NET and is supported on all OSs that support .NET. 
  • Use .NETStandard where possible, then .NET Core and finally as a last resort .NET Framework libraries which may or may not work.
  • Move all common class libraries to .NETStandard. 
  • Move all Services to .NET Core.
  • Move all UIs to .NET Core and pull in all of the other dependencies individually.

    https://msdn.microsoft.com/en-us/magazine/mt842506.aspx
    .NET Standard is a specification of APIs that all .NET implementations must provide. It brings consistency to the .NET family and enables you to build libraries you can use from any .NET implementation. It replaces PCLs for building shared components.
    .NET Core is an implementation of the .NET Standard that’s optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow. You can learn more about them at aka.ms/netstandardfaq and aka.ms/netcore.


    https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
    https://stackify.com/creating-net-core-windows-services/
The .NET Landscapedotnet-tomorrow

Testing Containers

Install Docker on a VM, Linux or Windows server.
OR
Install on your local Windows box with Docker for Windows (Windows 10, Windows Server 2016) https://docs.docker.com/docker-for-windows/install/ (I had to restart my Windows 10 machine twice in order for the Docker app to initially start correctly ).

Docker Registry

DockerHub is number one.
This are webservices that allow anyone to store Docker Containers. These Containers are then available to all or some (Repos can be used to privatice) a to use.
Inside the Corporate firewall you can use an internal Registry like Docker Trusted Registry DTR (not free) to store Containers.https://docs.docker.com/datacenter/dtr/2.4/guides/

Docker Container Development Flow

.NET Standard is a specification of APIs that all .NET implementations must provide. It brings consistency to the .NET family and enables you to build libraries you can use from any .NET implementation. It replaces PCLs for building shared components.
.NET Core is an implementation of the .NET Standard that’s optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow. You can learn more about them at aka.ms/netstandardfaq and aka.ms/netcore.

AWS

EC2, the cloud instance.
ECS, Container Management Service, a service to manage many EC2s and makes manage Docker itself.

Docker and Azure


Docker now works in Azure and you as a developer can author and run your .NET and ASP.NET5 apps as Docker Containers.

Docker Containers allow you to wrap your application up into a self contained application what requires nothing from the outside environment. This leads to a much safer deployment as your app is guaranteed to have all of the dependencies it needs and work exactly as it did in the developers workspace.

https://channel9.msdn.com/Series/Docker-for-NET-Developers
The video link above is series of videos which explains all. Below are some of the technologies mentioned throughout the videos.

NGINX (engine x)

A webserver which hides your real servers and allows you to easily manage load on your real servers.


Redis

A NoSQL database which stores the date in memory (very fast). Commonly used to store name/value pairs for use by multiple servers on one machine e.g. In the Cloud or Docker you could use Redis to store common variables so that all your containers have access to the same data.


Kestral

Message Queue, used by Docker, is required by Docker.


DNX

DotNet Execution Environment.
Allows .NET programs to run without Windows. The DNX contains all you need and pulls in dependencies using NuGet.
DNX was part of .NET and .NET Core.


Docker CLI

Command line for Docker. Download the Docker Client onto your development machine and execute commands which will communicate with the Docker Server.


Docker Image

A text file containing the definition for the Docker Container.

Docker Container

The instance created by Docker based on the contents of the Docker Image file.


Docker Hub

A place where you can get Docker Images created by other users.
Can be accessed from the website, through an API in code or through other Docker Image files.

Mono

An alternative to the Microsoft .NET Framework, it's open source.
.NET Framework for Windows, Linux and Mac.

.NET Core

Not the full .NET Framework, just enough to run .NET applications. 


.NET CLI

This is the specification for the .NET Framework. Used by others including Mono to write alternatives to Microsoft .NET Framework.


Windows Server Containers

Standalone processes hosted on Windows Server.

HyperV Containers

Standalone processes hosted on Windows Server but with a bit more security. Useful where multiple Containers belonging to more than 1 company are hosted on same Server.

Docker Compose

Tool for defining and running multiple Docker Containers.


Docker Swarm


Docker Container management tool.
Manage Docker Containers. Manage the network connections between containers.

Kubernetes

Docker Container management tool. 



dnu.cmd

.NET Development Utilities.
Part of DNX. Command line tool. Manages dependencies using NuGet.


TLS

Security at the Transport layer. Super-ceded by SSL.


Azure Endpoint

.....

Curl

Linux command to send and receive date over the web, supports all of the protocols like HTTP. 

Powershell.

Comments

Popular posts from this blog

dotNET - Debugging

Debugging with .NET MSIL assemblies Visual Studio and debugging the CLR are different, I'll talk about both. MSIL Assemblies Assemblies compiled with .NET tools such as the CLR compiler are compiled into a file which contains MSIL (Microsoft Intermediate Language). At runtime the contents of the assembly are loaded into the CLR and ran as machine code. When you compile an assembly in debug a PDB file is generated alongside the DLL or EXE you've just created. The link between these 2 files is that the PDB contains the line numbers of the methods and classes as well as the file names of the original source code that created the assembly. When you launch the debugger in Visual Studio the assembly is loaded into the Debugger (similar to the CLR) along with the PDB file. The debugger now uses your PDB file contents to match the running code found in the assembly to locations in source files (hopefully in your present project). CLR CLR Inside Out (msdn magazine) .NET Framework Tools:...

Installer CustomAction, Debugging the CustomAction, InstallState

Custom Action The Custom Action is added to the Setup Project, select the Project node and hit the Custom Action button. This allows you add an Action to a particular phase in the Installation. But first you must create the Custom Action. To Add a Custom Action you must first have a Custom Action created, this is usually in the form of a Installer Class, this should be created in a seperate project, the Installer Class is actually one of the File Templates in the C# Projects. So it's File->New Project and select Visual C# Projects. Then add a Class Library, this will prompt you for the Class Library Types , select "Installer Class". Walkthrough - Creating Custom Action (msdn). Also here's a more comprehensive document on Setup/Installer implementations, it delves into the Registry etc Getting Started with Setup Projects (SimpleTalk). Visual Studio Setup Projects and Custom Actions (Simple Talk). Create your Installer Class and then add it as a Custom Action to the ...

dotNET - Use app.config ApplicationSettings and UserSettings

When using Settings in an Assembly or .exe you can use the Settings Designer to generate a config file using Settings. The Settings Designer provides a wrapper class which allows you to provide defaults and access the config data using Properties. But what if you're not working inside that Assembly or .exe? this presents a problem. If your loading the Assembly externally and want to access that Assembly's .config file you'll probably wish to use something in the System.Configuration namespace... unfortunately it's not of much use if you've created the .config file from the Settings Designer in Visual Studio!! This is because the Designer creates Sections and ApplicationSettings and UserSettings, the System.Configuration namespace does not provide a method to access these (it has a method to access AppSettings which are a different thing. Below I've written a workaround which locates the app.config and accesses the ApplicationSettings and UserSettings using XML i...