-
Notifications
You must be signed in to change notification settings - Fork 569
22. Adding Docker Support
Now that we've kicked around the legacy version of the application, let's work on adding docker support by containerizing the WCF service.
In this scenario you will containerize a WCF service traditionally built with .NET Framework 4.x.
The diagram below shows the scenario for the containerized WCF service running in a development PC with Docker for Windows.
Adding docker support to your project is a trivial task in Visual Studio. Let's wrap the WCF service in a container. To do this:
- Right-click on the WCF project.
- Hover over 'add' in the context menu.
- Click 'Docker Support'
This actions does two things:
- It adds a Dockerfile and .dockerignore file to the selected project.
- It adds a docker-compose project to your solution.
Let's open up the dockerfile that was just added and paste in these changes:
FROM microsoft/wcf:4.7.1
EXPOSE 80
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
You can see that your custom WCF service image will be based on the microsoft/wcf:4.7.1 base image which is pretty similar to the ASP.NET base image but it has a few WCF activations in place.
Now let's edit the newly generated docker-compose files in the docker-compose project. First, open up docker-compose.yml.
Previously, our service was connected to a local database. Why not containerize the database as well? This will be easy. Under 'services', let's define our sql container:
version: '3.4'
services:
eshopwcfservice:
image: eshop/wcfservice
build:
context: ./src/eShopWCFService
dockerfile: Dockerfile
depends_on:
- sql.data
sql.data:
image: microsoft/mssql-server-windows-developer
We define a sql container with the name "sql.data". We're not altering our sql container, so we can simply reference the already published image, "mssql-server-windows-developer". Now, let's open up docker-compose.override.yml and make some changes there in order to customize our services:
services:
eshopwcfservice:
environment:
- ConnectionString=Server=sql.data;Database=eShopDatabase;User Id=sa;Password=YOUR-PASSWORD@@
ports:
- "80:80"
sql.data:
environment:
- SA_PASSWORD=YOUR-PASSWORD@@
- ACCEPT_EULA=Y
ports:
- "5433:1433"
At a high level, all that we're doing is defining some environmental variables in these containers to allow for connection between the database and the WCF service. We're also opening up and routing the correct ports between the host and containers so that requests on the host:port will flow to the correct container.
With our docker-compose changes wrapped up, let's hit F5 and kick off the build/debug. It may take a few minutes, as it may have to download the base container images that we're using.
You will know it has succeeded when a browser window opens and shows the CatalogService. We can check the docker processes running to verify that our containers launched by issuing 'docker ps', as shown below:
As we expected, we see one container to run our WCF service and another container to run our SQL database.
Continue on to learn about improvements which can be made in the WinForms app to make it run better on modern hardware: High DPI
- Home
- Release notes
- e-books
-
MVC & Web Forms Samples
- Tour of the "legacy" ASP.NET web apps to modernize
- How to containerize the .NET Framework web apps with Windows Containers and Docker
- Publishing your Windows Container images into a Docker Registry
- Deploying the Apps to Azure Web Apps for Containers
- Deploying the Apps to ACI (Azure Container Instances)
- Deploying your Windows Containers based app into Azure VMs (Including CI CD)
- Deploying into local Kubernetes in Windows 10 and Docker for Windows development environment
- How to deploy your Windows Containers based apps into Kubernetes in Azure Container Service (Including CI CD)
- How to add authentication authorization with Azure Active Directory
- How to migrate the SQL database to Azure with the Azure Database Migration Service
- Using Application Insights in eShopOnContainers
- N-Tier sample: WinForms app and WFC service
- ASP.NET to Azure App Service Migration Workshop