-
Notifications
You must be signed in to change notification settings - Fork 10.4k
08. Setting up and Deploying eShopOnContainers to Windows Containers
This is a draft page which will be evolving while our tests and dev regarding Windows Containers are completed.
Windows Containers support:
Windows Server 2016 - Production Environments
- Install Docker Enterprise Edition (Docker EE)
- Designed to run apps in production
- Call Microsoft for support. If it's a Docker rather than Windows problem, they escalate to Docker and get it solved
Windows 10 - Dev Environments
- Install Docker Community Edition (Docker CE, formerly Docker for Windows)
- Support via forums/GitHub
- Can switch between Windows container development and Linux (in VM). There is no plan to drop either OS from Docker CE
- Designed for devs only. Not production
Docker might provide per incident support system for Docker Community Edition, or provide a "EE Desktop" for developers, but it's their call to do so. Not Microsoft's.
In Windows 10 you need to set Docker to use "Windows container" instead of Linux containers (in Windows Server 2016 Windows Containers are used by default). To do this, first you must have enabled container support in Windows 10. In "Turn Windows features on/off" select "Containers":
/img/win-containers/enable-windows-containers.png
Then right click in the Docker icon on the notification bar and select the option "Switch to Windows Containers". If you don't see this option and see the option "Switch to Linux Containers" you're already using Windows Containers.
Due to a default NAT limitation in Windows (see https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/) you can't access your containers using localhost
from the host computer.
Instead of localhost you can use either an IP address from the network card of the host or you can also use the DockerNAT IP address, that is 10.0.75.1
. If you don't have that IP when you show info with ipconfig
, you'll need to switch to Linux Containers so it creates that Docker NAT and then go back to Windows Containers (right click on Docker icon on the task bar).
If you use start-windows-containers.ps1
to start the containers, that script will create environment variables with that IP for you, but if you directly use docker-compose, then you have to set the following environment variables:
Where you see 10.75.0.1
you could also use your network card IP discovered with ipconfig
, or a production DNS name or IP if this were a production deployment.
-
ESHOP_EXTERNAL_DNS_NAME_OR_IP
to10.75.0.1
-
ESHOP_AZURE_STORAGE_CATALOG_URL
tohttp://10.0.75.1:5101/api/v1/catalog/items/[0]/pic/
-
ESHOP_AZURE_STORAGE_MARKETING_URL
tohttp://10.0.75.1:5110/api/v1/campaigns/[0]/pic/
Note that the two last env-vars must be set only if you have not set them already because you were using Azure Storage for the images. If you are using azure storage for the images, you don't need to provide those URLs.
Once these variables are set you can run docker-compose to start the containers and navigate to http://10.0.75.1:5100
to view the MVC Web app.
Using start-windows-containers.ps1
is simpler as it'll create the env-vars for you.
Since eShopOnContainers is using Docker Multi-Stage builds, the compilation of the .NET application bits is now performed by Docker itself right before building the Docker images.
Although you can create the Docker images when trying to run the containers, let's split it in two steps, so it is clearer.
In order compile the bits and build the Docker images, run:
cd <root-folder-of--eshoponcontainers>
docker-compose -f docker-compose-windows.yml build
The esasiest way to run/start the Windows Containers of eShopOnContainers is by running this PowerShell script:
start-windows-containers.ps1
You can find this script at /cli-windows/start-windows-containers.ps1
Otherwise, you could also run it directly with docker-compose up
but then you'd be missing a few environment variables needed for Windows Containers. See the section below on the environment variables you will also need to configure.
Under the covers, in any case, the start-windows-containers.ps1 is running this command to deploy/run the containers:
docker-compose -f docker-compose-windows.yml -f docker-compose.override.yml -f docker-compose.override.windows.yml up
IMPORTANT: You need to use these three files when running docker-compose up and to have te environment variables related to the localhost loopback limitation mentioned at the end of this post.
Open a browser and navigate to the following URL:
http://10.0.75.1:5100
For RabbitMQ we are using the https://hub.docker.com/r/spring2/rabbitmq/ image, which provides a ready RabbitMQ to use. This RabbitMQ is configured to accept AMQP connections from the user admin:password
(this is different from the RabbitMQ Linux image which do not require any user/password when creating AMQP connections)
If you use start-windows-containers.ps1
script to launch the containers or include the file docker-compose.override.windows.yml
in the docker-compose
command, then the containers will be configured to use this login/password, so everything will work.
Note: Read this only if you use any other RabbitMQ image (or server) that have its own user/password needed.
We support any user/password needed using the environment variables ESHOP_SERVICE_BUS_USERNAME
and ESHOP_SERVICE_BUS_PASSWORD
. These variables are used to set a username and password when connecting to RabbitMQ. So:
- In Linux these variables should be unset (or empty) unless you're using any external RabbitMQ that requires any specific login/password
- In Windows these variables should be set
To set this variables you have two options
- Just set them on your shell
- Edit the
.env
file and add these variables
If you have set this images and you want to launch the containers you can use:
.\cli-windows\start-windows-containers.ps1 -customEventBusLoginPassword $true
When passing the parameter -customEventBusLoginPassword $true
to the script you are forcing to use the login/password set in the environment variables instead the default one (the one needed for spring2/rabbitmq).
If you prefer to use docker-compose
you can do it. Just call it without the docker-compose.override.windows.yml
file:
docker-compose -f docker-compose-windows.yml -f docker-compose.override.yml up
- System requirements
- Development setup
- Databases & containers
- Architecture
- Application
- Code
- Logging and Monitoring
- Tests