Deploy an ASP.NET container to a remote Docker host

Overview

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.

Prerequisites

The following is required to complete this tutorial:

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.

  1. From the Visual Studio menu, select File > New > Project.
  2. Under the Templates section of the New Project dialog box, select Visual C# > Web.
  3. Select ASP.NET Core Web Application (.NET Core).
  4. Give your new application a name (or take the default) and select OK.
  5. Under ASP.NET Core 1.1 Templates, select Web Application and select OK.

2. Add Docker support

  1. In the Visual Studio Solution Explorer, right-click the project and select Add > Docker Support from the context menu.

    Add Docker Support context menu

  2. 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.

    Docker files added to project

3. Use the DockerTask.ps1 PowerShell Script

  1. Open a PowerShell prompt to the root directory of your project.

    PS C:\Src\WebApplication1>
    
  2. 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
    
  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 
    
  4. 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:

    View your app