Docker is a lightweight container engine, similar in some ways to a virtual machine, which you can use to host applications and services. This tutorial walks you through using the Visual Studio Tools for Docker extension to deploy an ASP.NET Core app to a Docker host on Azure using PowerShell.
The following is required to complete this tutorial:
- Create an Azure Docker Host VM as described in How to use docker-machine with Azure
- Install the latest version of Visual Studio
- Download the Microsoft ASP.NET Core 1.0 SDK
- Install Docker for Windows
1. Create an ASP.NET Core web app
The following steps guide you through creating a basic ASP.NET Core app that will be used in this tutorial.
- From the Visual Studio menu, select File > New > Project.
- Under the Templates section of the New Project dialog box, select Visual C# > Web.
- Select ASP.NET Core Web Application (.NET Core).
- Give your new application a name (or take the default) and select OK.
- Under ASP.NET Core 1.1 Templates, select Web Application and select OK.
2. Add Docker support
In the Visual Studio Solution Explorer, right-click the project and select Add > Docker Support from the context menu.
Adding Docker support to an ASP.NET Core web project results in the addition of several Docker-related files being added to the project, including Docker-Compose files, deployment Windows PowerShell scripts, and Docker property files.
3. Use the DockerTask.ps1 PowerShell Script
Open a PowerShell prompt to the root directory of your project.
Validate the remote host is running. You should see state = Running
docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS MyDockerHost - azure Running tcp://xxx.xxx.xxx.xxx:2376 v1.10.3
Build the app using the -Build parameter
PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Build -Environment Release -Machine mydockerhost
PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Build -Environment Release
Run the app, using the -Run parameter
PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Run -Environment Release -Machine mydockerhost
PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Run -Environment Release
Once docker completes, you should see results similar to the following: