our blog


September 22, 2018 / by Adam Murray / In tech

Converting an ASP.NET Core Application to Docker on Windows 10

I’ve recently been working on an ASP.NET Core application in Visual Studio 2017 on Windows 10 and wanted to convert the project to use containers. A number of the steps were straight forward, however, I did hit a few hurdles that I want to cover in this blog post.

I wanted to run my app in a linux container on my windows 10 dev machine.

Visual Studio has tooling to create the basic dockerfile and docker-compose.yml which can be found be right clicking on your project and selecting ‘Add’ and then ‘Docker Support’.

This should create the necessary files and give you the option to launch the app in docker.

When I went to launch the app my build would fail with the following error

Unable to share C drive…..

So there seems to be a limitation with Docker for Windows where if you are using an AzureAD account you can’t share the drive. This post details the problem and suggests the workaround is to create a local account which I did.

Once I created the local account I was able to share the C drive in Docker using the local account I created.

This itself allowed the build to progress further however as I was running VS2017 under my AzureAD account I was still hitting issues as the build wanted to access two folders under my profile.

  • C:\Users\user\vsdbg
  • C:\Users\user\.nuget

To solve this issue I gave the local docker account I created earlier access to those two folders. At this point my build completed successfully but my app would error as I was using localdb as my dev sql database.

At this point I decided I wanted to use a SQL docker container. I modified my docker-compose.yml file as follows

version: '3.4'

    image: ${DOCKER_REGISTRY}app
      context: .
      dockerfile: App/Dockerfile
      - db
    image: "microsoft/mssql-server-linux"

I then updated my docker-compose.override.yml file as follows:

version: '3.4'

      ConnectionStrings__DefaultConnection: "Server=db;Database=app;ConnectRetryCount=0;User=sa;Password=Your_password123;MultipleActiveResultSets=true"
      - "80"
      SA_PASSWORD: "Your_password123"
      ACCEPT_EULA: "Y"

Now, when I launched my app it started two containers and the asp.net app was able to use sql in the second container.

Next steps are to update my Azure DevOps build process to handle the container workflow and create a new release process to deploy the app to Azure container instances.