{"id":7845,"date":"2016-11-16T09:30:44","date_gmt":"2016-11-16T16:30:44","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=7845"},"modified":"2016-11-16T09:30:44","modified_gmt":"2016-11-16T16:30:44","slug":"new-docker-tools-for-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/new-docker-tools-for-visual-studio\/","title":{"rendered":"Put a .NET Core App in a Container with the new Docker Tools for Visual Studio"},"content":{"rendered":"<p>By now hopefully you\u2019ve heard the good news that we\u2019ve added first class support for building and running .NET applications inside of <a href=\"https:\/\/www.docker.com\/what-docker\">Docker containers<\/a> in Visual Studio 2017 RC.\u00a0 Visual Studio 2017 and Docker support building and running .NET applications using Windows containers (on Windows 10\/Server 2016 only), and .NET Core applications on Linux containers, including the ability to publish and run Linux containers on Microsoft\u2019s Azure App Service.<\/p>\n<p>Docker containers\u00a0package an application\u00a0with everything\u00a0it needs to run: code, runtime, system tools, system libraries \u2013 anything\u00a0you would install\u00a0on a server.\u00a0 Put simply, a container is an isolated place where an application can run without affecting the rest of the system, and without the system affecting the application. This makes them an ideal way to package and run applications in production environments, where historically constraints imposed by the production environment (e.g. which version of the .NET runtime the server is running) have dictated development decisions.\u00a0 Additionally, Docker containers are very lightweight which enable scaling applications quickly by spinning up new instances.<\/p>\n<p>In this post, I\u2019ll focus on creating a .NET Core application, publishing it to the Azure App Service Linux Preview and setting up continuous build integration and delivery to the Azure Container Service.<\/p>\n<h2>Getting Started<\/h2>\n<p>To get started in Visual Studio 2017 you need to install the \u201c.NET Core and Docker (Preview)\u201d workload in the new Visual Studio 2017 installer<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/VS_Installer.png\"><img decoding=\"async\" width=\"990\" height=\"553\" class=\"aligncenter wp-image-8026 size-full\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/VS_Installer-1.png\" \/><\/a>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/13-runningInAzureContainer.png\"><\/a><\/p>\n<p>Once it finishes installing, you\u2019ll need to install <a href=\"https:\/\/docs.docker.com\/docker-for-windows\/\">Docker for Windows<\/a> (if you want to use Windows containers on Windows 10 or Server 2016 you\u2019ll need the <a href=\"https:\/\/download.docker.com\/win\/beta\/InstallDocker.msi\">Beta channel <\/a>and the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/virtualization\/windowscontainers\/quick_start\/quick_start_windows_10\">Windows 10 Anniversary Edition<\/a>, if you want Linux containers you can choose either the Stable or Beta channel installers).<\/p>\n<p>After you\u2019ve finished installing Docker, you\u2019ll need to share a drive with it where your images will be built to and run from.\u00a0 To do this:<\/p>\n<ul>\n<li>Right click on the Docker system tray icon and choose settings<\/li>\n<li>Choose the \u201cShared Drives\u201d tab<\/li>\n<li>Share the drive your images will run from (this is the same drive the Visual Studio project will live on)<\/li>\n<\/ul>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/2-driveConfig.png\"><img decoding=\"async\" width=\"879\" height=\"524\" class=\"aligncenter size-large wp-image-7886\" alt=\"2-driveconfig\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/2-driveConfig-1024x611-1.png\" \/><\/a><\/p>\n<h2>Creating an application with Docker support<\/h2>\n<p>Now that Visual Studio and Docker are installed and configured properly let\u2019s create a .NET Core application that we\u2019ll run in a Linux container.<\/p>\n<p>On the ASP.NET application dialog, there is a checkbox that allows us to add Docker support to the application as part of project creation.\u00a0 For now, we\u2019ll to skip this, so we can see how to add Docker support existing applications.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/3-webapplication.png\"><img decoding=\"async\" width=\"879\" height=\"576\" class=\"aligncenter size-large wp-image-7895\" alt=\"3-webapplication\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/3-webapplication-1.png\" \/><\/a>Now that we have our basic web application, let\u2019s add a quick code snippet to the \u201cAbout\u201d page that will show what operating system the application is running on<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/4-about.png\"><img decoding=\"async\" width=\"879\" height=\"181\" class=\"aligncenter size-large wp-image-7905\" alt=\"4-about\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/4-about-1.png\" \/><\/a>Next, we&#8217;ll hit Ctrl + F5 to run it inside IIS Express, we can see we\u2019re running on Windows as we would expect.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/5-runNatively.png\"><img decoding=\"async\" width=\"497\" height=\"368\" class=\"aligncenter size-large wp-image-7915\" alt=\"5-runnatively\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/5-runNatively-1.png\" \/><\/a>Now, to add Docker support to the application, right click on the project in Solution Explorer, choose Add, and then \u201cDocker Project Support\u201d (use \u201cDocker Solution Support\u201d to create containers for multiple projects).<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/6-addDockerSupport.png\"><img decoding=\"async\" width=\"879\" height=\"613\" class=\"aligncenter size-large wp-image-7925\" alt=\"6-adddockersupport\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/6-addDockerSupport-1.png\" \/><\/a>You\u2019ll see that the \u201cStart\u201d button has changed to say \u201cDocker\u201d and several Docker files have been added to the project.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/7-additionalDockerFiles.png\"><img decoding=\"async\" width=\"879\" height=\"530\" class=\"aligncenter size-large wp-image-7935\" alt=\"7-additionaldockerfiles\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/7-additionalDockerFiles-1024x618-1.png\" \/><\/a>Let\u2019s hit Ctrl+F5 again and we can see that the app is now running inside a Linux container locally.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/8-runningInLinuxContainer.png\"><img decoding=\"async\" width=\"527\" height=\"363\" class=\"aligncenter size-large wp-image-7945\" alt=\"8-runninginlinuxcontainer\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/8-runningInLinuxContainer-1.png\" \/><\/a><\/p>\n<h2>Running the application in Azure<\/h2>\n<p>Now let\u2019s publish the app to Microsoft Azure App Service, which now offers the ability to run Linux Docker containers in a preview form.<\/p>\n<p>To do this, I\u2019ll right click on the app and choose \u201cPublish\u201d.\u00a0 This will open our brand new publish page.\u00a0 Click the \u201cProfiles\u201d dropdown and select \u201cNew Profile\u201d, and then choose \u201cAzure App Service Linux (Preview)\u201d and click \u201cOK\u201d<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/9-publishToAzureContainer.png\"><img decoding=\"async\" width=\"879\" height=\"551\" class=\"aligncenter size-large wp-image-7955\" alt=\"9-publishtoazurecontainer\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/9-publishToAzureContainer-1.png\" \/><\/a><\/p>\n<p>Before proceeding it\u2019s important to understand the anatomy of how a Docker application works in a production environment:<\/p>\n<ul>\n<li>A container registry is created that the Docker image is published to<\/li>\n<li>The App Service site is created that downloads the image from the container registry and runs it<\/li>\n<li>At any time, you can push a new image to the container registry which will then result in the copy running in App Service being updated.<\/li>\n<\/ul>\n<p>With that understanding, let\u2019s proceed to publishing our application to Azure.\u00a0 The next thing we\u2019ll see is the Azure provisioning dialog.\u00a0 There are a couple of things to note about using this dialog in the RC preview:<\/p>\n<ul>\n<li>If you are using an existing Resource Group, it must be in the same region as the App Service Plan you are creating<\/li>\n<li>If you are creating a new Resource Group, you must set the Container Registry and the App Service plan to be in the same region (e.g. both must be in \u201cWest US\u201d)<\/li>\n<li>The VM size of the App Service Plan must be \u201cS1\u201d or larger<\/li>\n<\/ul>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/10-publishToAzureContainerPart2.png\"><img decoding=\"async\" width=\"879\" height=\"659\" class=\"aligncenter size-large wp-image-7965\" alt=\"10-publishtoazurecontainerpart2\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/10-publishToAzureContainerPart2-1.png\" \/><\/a>When we click \u201cOK\u201d it will take about a minute, and then we\u2019ll return to the \u201cPublish\u201d page, where we\u2019ll see a summary of the publish profile we just created.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/11-publishToAzureContainerPart3.png\"><img decoding=\"async\" width=\"788\" height=\"446\" class=\"aligncenter size-large wp-image-7966\" alt=\"11-publishtoazurecontainerpart3\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/11-publishToAzureContainerPart3-1.png\" \/><\/a>Now we click \u201cPublish\u201d and it will take about another minute during which time you\u2019ll see a Docker command prompt pop up<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/12-publishToAzureContainerPart4.png\"><img decoding=\"async\" width=\"879\" height=\"197\" class=\"aligncenter size-large wp-image-7975\" alt=\"12-publishtoazurecontainerpart4\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/12-publishToAzureContainerPart4-1024x229-1.png\" \/><\/a>When the application is ready, your browser will open to the site, and we can see that we\u2019re running on Linux in Azure!<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/13-runningInAzureContainer.png\"><img decoding=\"async\" width=\"580\" height=\"337\" class=\"aligncenter size-large wp-image-7985\" alt=\"13-runninginazurecontainer\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/13-runningInAzureContainer-1.png\" \/><\/a><\/p>\n<h2>Setting up continuous build integration and delivery to the Azure Container Service<\/h2>\n<p>Now let\u2019s setup continuous build delivery to Microsoft Azure Container Service. To do this, I\u2019ll right click on the project and choose &#8220;Configure Continuous Delivery\u2026&#8221;.\u00a0 This will bring up a continuous delivery configuration dialog.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/EntryPoint.png\"><img decoding=\"async\" width=\"676\" height=\"638\" class=\"aligncenter size-full wp-image-7995\" alt=\"Configure Continuous Delivery\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/EntryPoint-1.png\" \/><\/a><\/p>\n<p>On the Configure Continuous Delivery dialog, select a user account with a valid Azure subscription as well as An Azure subscription with a valid Container registry and a DC\/OC orchestrator Azure Container Service.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/ConfigureContinuousDelivery.png\"><img decoding=\"async\" width=\"881\" height=\"519\" class=\"aligncenter size-full wp-image-7996\" alt=\"Configure Continuous Delivery\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/ConfigureContinuousDelivery-1.png\" \/><\/a><\/p>\n<p>When done, click OK to start the setup process. A dialog will pop-up to explain that the setup process started.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/ConfigurationStarted.png\"><img decoding=\"async\" width=\"471\" height=\"175\" class=\"aligncenter size-full wp-image-8005\" alt=\"Configuration Started\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/ConfigurationStarted-1.png\" \/><\/a><\/p>\n<p>As the continuous build delivery setup can take several minutes to complete, you may consult the &#8216;Continuous Delivery Tools&#8217; output tool window later to inspect the progress.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/OutputSetupStarted.png\"><img decoding=\"async\" width=\"879\" height=\"167\" class=\"aligncenter wp-image-8015 size-large\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/OutputSetupStarted-1024x195-1.png\" \/><\/a><\/p>\n<p>Upon successful completion of the setup, the output window will display the configuration details used to create the build and release definitions on VSTS to enable continuous build delivery for the project to the Azure Container Service.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/OutputSetupComplete.png\"><img decoding=\"async\" width=\"879\" height=\"153\" class=\"aligncenter size-large wp-image-8025\" alt=\"Setup Complete\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2016\/11\/OutputSetupComplete-1024x178-1.png\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>Please <a href=\"https:\/\/www.visualstudio.com\/downloads\/\">download Visual Studio 2017<\/a> today, and give our .NET Core and Docker experience a try.\u00a0 It\u2019s worth noting that this is a preview of the experience, so please help us make it great by providing feedback in the comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By now hopefully you\u2019ve heard the good news that we\u2019ve added first class support for building and running .NET applications inside of Docker containers in Visual Studio 2017 RC.\u00a0 Visual Studio 2017 and Docker support building and running .NET applications using Windows containers (on Windows 10\/Server 2016 only), and .NET Core applications on Linux containers, [&hellip;]<\/p>\n","protected":false},"author":405,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509,327],"tags":[30,7265,7510,1696],"class_list":["post-7845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore","category-azure","tag-announcement","tag-announcements","tag-app-service","tag-container"],"acf":[],"blog_post_summary":"<p>By now hopefully you\u2019ve heard the good news that we\u2019ve added first class support for building and running .NET applications inside of Docker containers in Visual Studio 2017 RC.\u00a0 Visual Studio 2017 and Docker support building and running .NET applications using Windows containers (on Windows 10\/Server 2016 only), and .NET Core applications on Linux containers, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/7845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/405"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=7845"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/7845\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=7845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=7845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=7845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}