-
Notifications
You must be signed in to change notification settings - Fork 5.6k
06. Deploying as a Windows Container into a Windows Container host in Azure
To deploy the eShopOnWeb sample to a Windows 2016 virtual machine running Docker on Azure, from Visual Studio, follow these step-by-step instructions:
- Log into Azure and click on the plus symbol(
+
) to create a new resource. Then selectcompute
andsee all
- In the search box enter
containers
and then selectWindows Server 2016 Datacenter - with Containers
- Click create
- 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
- Select a size for the virtual machine. DS1_V2 is sufficient for our needs. Click
select
- In the settings click on
Network security group
then clickAdd inbound rule
- Create a rule to expose the Docker agent port, 2375, by entering a name for the rule, a priority and the port. Click
Ok
- 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 theService
drop down. ClickOk
- Click
Ok
on the settings blade - On the purchase blade click
Purchase
- The virtual machine will now be provisioned. Click on
Virtual Machines
and then select your new virtual machine.
- 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.
- Launch the connection by clicking on the downloaded connection file
- Agree to connect
- 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 onOK
- 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 theWindows Firewall with Advanced Security
- In the firewall settings click on
Inbound Rules
thenNew Rule...
- Select
Port
as the rule type and clickNext
- Select
Specific local ports
and enter2375
. ClickNext
- Select
Allow the connection
and clickNext
- Leave the settings on the Profile page unchanged and click
Next
- Enter a name such as
Docker
for the firewall rule and clickFinish
- In the firewall settings click on
Inbound Rules
thenNew Rule...
- Select
Port
as the rule type and clickNext
- Select
Specific local ports
and enter80
. ClickNext
- Select
Allow the connection
and clickNext
- Leave the settings on the Profile page unchanged and click
Next
- Enter a name such as
Web
for the firewall rule and clickFinish
-
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
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.
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.
- Click on the
start
button and search forcomputer
. Right click onThis PC
and selectproperties
- Select
Advanced system settings
- Click
Environment Variables
- Add a new system variable called
DOCKER_HOST
set it to betcp://<ip address of your virtual machine>:2375
-
Clone or download the eShopOnWeb sample to a folder on your local machine.
-
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
-
Right click on the
Web
project in Visual Studio and select theAdd
menu thenDocker Support
.
- Select
Windows
and click onOK
. This will create a new project in your solution calleddocker-compose
. This project contains the settings for deploying to Docker.
- Update the
docker-compose.yml
to listen to and forward port 80 to port 5106. Change the line
ports:
- "80"
to
ports:
- "80:5106"
-
Build the project under
Release
configuration. This will deploy the image to the remote Docker daemon -
Open an instance of powershell and run
docker run -p <ip address of your virtual machine>:80:80 web -t
- Direct your web browser to http://. You should see an instance of the eShopOnWeb site running
- Getting Started for Beginners (with video)
-
Walkthroughs
- Deploying to Azure App Service from Visual Studio
- Deploying to Azure App Service from Azure Portal
- Deploying to Azure App Service from Visual Studio for Mac
- Running as a Linux Container locally in Visual Studio
- Deploying as a Linux Container into Azure App Service
- Running in a Windows Container locally in Visual Studio
- Running as a Linux Container locally in Visual Studio for Mac
- Deploying as a Windows Container into a Windows Container host in Azure
- Working with the Project and Adding New Features using Visual Studio for Mac