Skip to content

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

Sarah Dutkiewicz edited this page Feb 7, 2025 · 2 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 image

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

  3. Click Create. image

  4. 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 OK image

  5. Select a size for the virtual machine. DS1_V2 is sufficient for our needs. Click Select. image

  6. In the Settings, click on Network security group then click Add inbound rule. image

  7. Create a rule to expose the Docker agent port, 2375, by entering a name for the rule, a priority and the port. Click OK. image

  8. 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. image

  9. Click OK on the Settings blade.

  10. On the Purchase blade, click Purchase image

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

  12. 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. image

Configuring Docker on the Virtual Machine

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

  2. Agree to connect image

  3. 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. image

  4. 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. image

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

  6. Select Port as the rule type and click Next. image

  7. Select Specific local ports and enter 2375. Click Next. image

  8. Select Allow the connection and click Next. image

  9. Leave the settings on the Profile page unchanged and click Next. image

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

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

  12. Select Port as the rule type and click Next. image

  13. Select Specific local ports and enter 80. Click Next. image

  14. Select Allow the connection and click Next. image

  15. Leave the settings on the Profile page unchanged and click Next. image

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

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

    image

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

  2. Select Advanced system settings. image

  3. Select Environment Variables. image

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

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.

    image

  4. 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. image

  5. Update the docker-compose.yml to listen to and forward port 80 to port 5106. Change the line

    ports:
       - "80"
    

    to

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

  7. Open an instance of PowerShell and run:

    docker run -p <ip address of your virtual machine>:80:80 web -t

  8. Direct your web browser to http://your_ip_address_of_your_virtual_machine. You should see an instance of the eShopOnWeb site running

    image