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 2015 Tools for Docker extension to deploy an ASP.NET Core app to a Docker host on Azure using PowerShell.

Prerequisites

The following is needed to complete this tutorial:

1. Create an ASP.NET Core web app

The following steps will 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 Templates, select Web Application and select OK.
  6. Unselect Host in the cloud. You'll be using Docker as your deployment solution.

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

Note

If using the Docker for Windows Beta, open Properties\Docker.props, remove the default value and restart Visual Studio for the value to take effect.

<DockerMachineName Condition="'$(DockerMachineName)'=='' "></DockerMachineName>

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
    
    Note

    If you're using the Docker Beta, your host won't be listed here.

  3. Build the app using the -Build parameter

    PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Build -Environment Release -Machine mydockerhost
    
    Note

    If you're using the Docker Beta, omit the -Machine argument

    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
    
    Note

    If you're using the Docker Beta, omit the -Machine argument

    PS C:\Src\WebApplication1> .\Docker\DockerTask.ps1 -Run -Environment Release 
    

    Once docker completes, you should see results similar to the following:

    View your app