-
Notifications
You must be signed in to change notification settings - Fork 592
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.
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.
As you will read about later in the wiki, there is a caveat associated with adding docker support to a WCF service. Let's open up the dockerfile that was just added and paste in these changes:
FROM microsoft/aspnet:4.6.2
#These features are required for WCF
RUN Add-WindowsFeature Web-Server; \
Add-WindowsFeature NET-WCF-TCP-Activation45; \
Add-WindowsFeature NET-WCF-HTTP-Activation45; \
Add-WindowsFeature Web-WebSockets
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
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:
services:
eshopwcfservice:
...
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:
services:
eshopwcfservice:
environment:
- ConnectionString=Server=sql.data;Database=eShopDatabase;User Id=sa;Password=Testing11@@
ports:
- "80:80"
sql.data:
environment:
- SA_PASSWORD=Testing11@@
- 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