-
Notifications
You must be signed in to change notification settings - Fork 51
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 select compute and see 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
OK
-
Select a size for the virtual machine.
DS1_V2
is sufficient for our needs. ClickSelect
. -
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 enterfirewall
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
. -
Select
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 port80
to port5106
. Change the lineports: - "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://your_ip_address_of_your_virtual_machine. You should see an instance of the eShopOnWeb site running