{"id":133,"date":"2015-11-05T18:59:42","date_gmt":"2015-11-05T18:59:42","guid":{"rendered":"http:\/\/michaelstoica.com\/?p=133"},"modified":"2015-11-05T19:03:35","modified_gmt":"2015-11-05T19:03:35","slug":"windows-server-containers","status":"publish","type":"post","link":"https:\/\/michaelstoica.com\/site\/windows-server-containers\/","title":{"rendered":"Windows Server Containers"},"content":{"rendered":"<p>Windows Server 2016 Technical Preview 3 brings one of the most expected feature, Windows Containers. I know that it&#8217;s been a long time since it has been released and that there are a lot of articles about Windows Containers on the internet, but I&#8217;ve been busy with some personal stuff :).<\/p>\n<p><strong>What are Containers?<\/strong><\/p>\n<p>Containers are something new to the Microsoft world, but it&#8217;s been around for a while in the Linux world. This is a new layer of virtualisation, called OS virtualisation, where a container host is deployed either on a virtual machine or a physical host. \u00a0On this container host you can deploy container os images as many as you want and they will share the container host resources.\u00a0The nice thing about container is that they boot very fast and in a couple of seconds you have a full copy of Windows Server Core with IIS installed on it, way more faster than creating a virtual machine.<\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Containers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-139\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Containers.png\" alt=\"Containers\" width=\"2105\" height=\"1145\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Containers.png 2105w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Containers-300x163.png 300w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Containers-1024x557.png 1024w\" sizes=\"auto, (max-width: 2105px) 100vw, 2105px\" \/><\/a><\/p>\n<p><strong>Windows\u00a0Containers vs. Hyper-V Containers<\/strong><\/p>\n<p>Microsoft is going to provide two types of Containers, Windows Containers and Hyper-V Containers.\u00a0The Hyper-V Containers requires Hyper-V Hypervisor and adds an extra layer of security and isolation, especially for application that shouldn&#8217;t share the same operating system. Both types of Containers use the same image format meaning that a Windows Container can be converted into a Hyper-V container and the other way around.<\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Capture.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-141\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Capture.png\" alt=\"Capture\" width=\"1305\" height=\"648\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Capture.png 1305w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Capture-300x149.png 300w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/Capture-1024x508.png 1024w\" sizes=\"auto, (max-width: 1305px) 100vw, 1305px\" \/><\/a><\/p>\n<p>Now let&#8217;s deploy a Windows Container. You have 3 options when deploying a Windows Container:<\/p>\n<ul>\n<li>You can deploy on Virtual Machine running Windows Server Technical Preview 3 Server Core<\/li>\n<li>You can deploy it on a new Virtual Machine<\/li>\n<li>Or in Azure<\/li>\n<\/ul>\n<p>If you are going to deploy it on a VM running WSTP3 Server Core as I did, you need to run\u00a0<em>wget -uri https:\/\/aka.ms\/setupcontainers -OutFile C:\\ContainerSetup.ps1<\/em> which will donwload a script that will configure the Windows Server Container components for you. If you want to deploy on a new Virtual Machine you need to run<em>\u00a0wget -uri https:\/\/aka.ms\/newcontainerhost -OutFile New-ContainerHost.ps1. \u00a0<\/em><\/p>\n<p>Thanks to\u00a0Aidan Finn which \u00a0explains very well in his <a href=\"http:\/\/www.aidanfinn.com\/?p=18881\">article <\/a>what this script does and how can you change the IP Address range used . What I&#8217;ve did, I copied the ContainerSetup.ps1 script and edited it to make it use the DHCP and not NAT. You can easily activate DHCP when running the script by typing .\\ContainerSetup.ps1 -UseDHCP. This might take a while depending on your internet connection.<\/p>\n<p>After that will have a container up and running on which we can run some commands. The command\u00a0<em>Get-ContainerImage\u00a0<\/em>will show you the default WindowsServerCore image. Based on this image, you can create your own images.<\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-containerimage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-147\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-containerimage.png\" alt=\"get-containerimage\" width=\"872\" height=\"163\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-containerimage.png 872w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-containerimage-300x56.png 300w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/a><\/p>\n<p>Before creating the first container you should run\u00a0<em>Get-VMSwitch\u00a0<\/em>to see what is the name of the switch available.<\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-vmswitch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-149\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-vmswitch.png\" alt=\"get-vmswitch\" width=\"857\" height=\"67\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-vmswitch.png 857w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/get-vmswitch-300x23.png 300w\" sizes=\"auto, (max-width: 857px) 100vw, 857px\" \/><\/a><\/p>\n<p>Now let&#8217;s create our first container by running\u00a0<em><span class=\"hljs-variable\">$container<\/span> = New-Container -Name <span class=\"hljs-string\">&#8220;TestContainer&#8221;<\/span> -ContainerImageName WindowsServerCore -SwitchName <span class=\"hljs-string\">&#8220;Virtual Switch&#8221;<\/span><\/em><span class=\"hljs-string\">\u00a0 and then run <em>Get-Container.\u00a0<\/em> The Container state will be off and you can start it by running\u00a0<em>Start-Container -Name &#8220;TestContainer&#8221;\u00a0<\/em>and you can open a powershell session with\u00a0<em> Enter-PSSession -ContainerID $container.ContainerId -RunAsAdministrator.<\/em><\/span><\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/insidecontainer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-150\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/insidecontainer.png\" alt=\"insidecontainer\" width=\"890\" height=\"134\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/insidecontainer.png 890w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/insidecontainer-300x45.png 300w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/a><\/p>\n<p>Now that we have a container, we can create our ContainerImage using the command\u00a0<em><span class=\"hljs-variable\">$newimage<\/span> = New-ContainerImage -ContainerName TestContainer\u00a0-Publisher Demo -Name testimage\u00a0-Version <span class=\"hljs-number\">1.0.<\/span><\/em><\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/new-containerimage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-151\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/new-containerimage.png\" alt=\"new-containerimage\" width=\"888\" height=\"90\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/new-containerimage.png 888w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/new-containerimage-300x30.png 300w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/a><\/p>\n<p>We can create a new container based on the image recently created\u00a0<em><span class=\"hljs-variable\">$newcontainer<\/span> = New-Container -Name <span class=\"hljs-string\">&#8220;NewContainer&#8221;<\/span> -ContainerImageName newimage -SwitchName <span class=\"hljs-string\">&#8220;Virtual Switch&#8221;<\/span><\/em><\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/newcontainer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-152\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/newcontainer.png\" alt=\"newcontainer\" width=\"865\" height=\"191\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/newcontainer.png 865w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/newcontainer-300x66.png 300w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/a><\/p>\n<p>If you don&#8217;t want to go through all this process you can use the template from Microsoft Azure to deploy a new Container Host.<\/p>\n<p><a href=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/azurecontainer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-153\" src=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/azurecontainer.png\" alt=\"azurecontainer\" width=\"1265\" height=\"868\" srcset=\"https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/azurecontainer.png 1265w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/azurecontainer-300x206.png 300w, https:\/\/michaelstoica.com\/site\/wp-content\/uploads\/2015\/11\/azurecontainer-1024x703.png 1024w\" sizes=\"auto, (max-width: 1265px) 100vw, 1265px\" \/><\/a><\/p>\n<p>If you didn&#8217;t understand the container concept you can check Mark Russnovich <a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/containers-docker-windows-and-trends\/\">article <\/a>about container and also Aidan Finn has some articles on his own <a href=\"http:\/\/www.aidanfinn.com\/\">blog <\/a>and also on www.petri.com where he explains very well the container stuff.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows Server 2016 Technical Preview 3 brings one of the most expected feature, Windows Containers. I know that it&#8217;s been a long time since it&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/michaelstoica.com\/site\/windows-server-containers\/\">Continue reading<span class=\"screen-reader-text\">Windows Server Containers<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[21,15,8,19],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-general","tag-containers","tag-hyper-v","tag-virtualization","tag-windows-server-2016","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p63Lge-29","_links":{"self":[{"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":14,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/posts\/133\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelstoica.com\/site\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}