Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

06. Deploying as a Windows Container into a Windows Container host in Azure

Steve Smith edited this page Jun 4, 2019 · 4 revisions

To deploy the eShopOnWeb sample to a Windows 2016 virtual machine running Docker on Azure, from Visual Studio, follow these step-by-step instructions:

Provision a Virtual Machine to Host Docker

  1. Log into Azure and click on the plus symbol(+) to create a new resource. Then select compute and see all

Add + then compute and see all.

  1. In the search box enter containers and then select Windows Server 2016 Datacenter - with Containers

Search for containers.

  1. Click create

Click create.

  1. Enter a name for the virtual machine. Also provide a user name and a password to log into the virtual machine. Be sure to record the password as it will be needed in subsequent steps. Choose either an existing resource group or create a new one. Finally, click select

Enter name, login credentials and resource group.

  1. Select a size for the virtual machine. DS1_V2 is sufficient for our needs. Click select

Select a size of virtual machine

  1. In the settings click on Network security group then click Add inbound rule

Add a new security group rule

  1. Create a rule to expose the Docker agent port, 2375, by entering a name for the rule, a priority and the port. Click Ok

Add a rule for the Docker agent

  1. Create a rule to expose the Web Server which will be running on the Docker agent. Entering a name for the rule, a priority and select HTTP from the Service drop down. Click Ok

Add a rule for the web server

  1. Click Ok on the settings blade
  2. On the purchase blade click Purchase

Click on purchase

  1. The virtual machine will now be provisioned. Click on Virtual Machines and then select your new virtual machine.

Click on virtual machines and then your newly provisioned machine

  1. Click on Connect to download the remote connection file for the virtual machine. You may also wish to record the IP address of your machine at this time - it will be needed later.

Download the connection file

Configuring Docker on the Virtual Machine

  1. Launch the connection by clicking on the downloaded connection file

Launching the connection

  1. Agree to connect

Connection

  1. Enter the password and user name recorded earlier. You may need to click on More Choices to access the user name and password boxes. Click on OK

Enter the user name and password

  1. The firewall on the server must now have ports opened to allow access to the Docker daemon and container. Click on the start menu and enter firewall then click on the Windows Firewall with Advanced Security

Search for firewall and click on the Windows Firewall

  1. In the firewall settings click on Inbound Rules then New Rule...

Click Inbound Rule and then New Rule

  1. Select Port as the rule type and click Next

Set port as the type of firewall

  1. Select Specific local ports and enter 2375. Click Next

Enter port 2375

  1. Select Allow the connection and click Next

Allow the connection

  1. Leave the settings on the Profile page unchanged and click Next

Leave settings unchanged

  1. Enter a name such as Docker for the firewall rule and click Finish

Enter name for the rule and click next

  1. In the firewall settings click on Inbound Rules then New Rule...

Click Inbound Rule and then New Rule

  1. Select Port as the rule type and click Next

Set port as the type of firewall

  1. Select Specific local ports and enter 80. Click Next

Enter port 80

  1. Select Allow the connection and click Next

Allow the connection

  1. Leave the settings on the Profile page unchanged and click Next

Leave settings unchanged

  1. Enter a name such as Web for the firewall rule and click Finish

Enter name for the rule and click next

  1. By default the Docker daemon doesn't listen on external ports so we need to enable that. Open an administrative powershell window and enter

    stop-service docker
    &"C:\Program Files\Docker\dockerd.exe" -H tcp://0.0.0.0:2375
    

    Docker daemon running on Windows Server 2016

    The server should now be set up to allow remote Docker connections. Note: It is not secure to run the Docker daemon exposed to the Internet and without any authentication. For the purposes of this tutorial we'll allow it but in real world applications other approaches are recommended.

Configure Your Computer to Talk to Docker on the Virtual Machine

Your computer needs to be configured to talk to the Docker daemon on the virtual machine that was just set up. To do this we'll need to set an environment variable pointing Docker to the remote daemon.

  1. Click on the start button and search for computer. Right click on This PC and select properties

Open This PC properties

  1. Select Advanced system settings

Advanced system settings

  1. Click Environment Variables

Environment Variables

  1. Add a new system variable called DOCKER_HOST set it to be tcp://<ip address of your virtual machine>:2375

Advanced system settings

Build and Run the Container

  1. Clone or download the eShopOnWeb sample to a folder on your local machine.

  2. Ensure the computer on which you're running has Windows containers enabled. You can read how perform the one-time setup on the Docker Blog

  3. Right click on the Web project in Visual Studio and select the Add menu then Docker Support.

Add docker support by clicking Add > Docker Support.

  1. Select Windows and click on OK. This will create a new project in your solution called docker-compose. This project contains the settings for deploying to Docker.

Select Windows in the Docker Support Options dialog

  1. Update the docker-compose.yml to listen to and forward port 80 to port 5106. Change the line
ports:
      - "80"

to

ports:
      - "80:5106"
  1. Build the project under Release configuration. This will deploy the image to the remote Docker daemon

  2. Open an instance of powershell and run

  docker run -p <ip address of your virtual machine>:80:80 web -t
  1. Direct your web browser to http://. You should see an instance of the eShopOnWeb site running

The site running in a windows container

Clone this wiki locally