Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

22. Adding Docker Support

eiximenis edited this page Apr 17, 2018 · 3 revisions

Now that we've kicked around the legacy version of the application, let's work on adding docker support by containerizing the WCF service.

Add Support

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:

  1. Right-click on the WCF project.
  2. Hover over 'add' in the context menu.
  3. Click 'Docker Support'

This actions does two things:

  1. It adds a Dockerfile and .dockerignore file to the selected project.
  2. It adds a docker-compose project to your solution.

Edit the dockerfile

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} .

Edit docker-compose files

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.

Test our changes

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.

Next Steps

Continue on to learn about improvements which can be made in the WinForms app to make it run better on modern hardware: High DPI

Clone this wiki locally