IdentityServer4 on Docker (ASP.NET Core 1.0)

In my previous article I showed how to run Identity Server 4 on Docker targeting ASP.NET Core RC1. In June .NET Core 1.0 and ASP.NET Core 1.0 was released which had some breaking changes. In this post I’ll show what changes are required to run Identity Server 4 targeting ASP.NET Core 1.0 on Docker. I will take up from where we left off on my previous post, so check that out before continuing.

What changed in ASP.NET Core 1.0?

There are some breaking changes in ASP.NET Core 1.0. In this guide I only focus on changes needed to run IdSrv4 on docker. For complete detail on how to migrate an application to ASP.NET Core 1.0 from RC1, check out official guide.

I have changed my sample application to target ASP.NET Core 1.0 and made all the above changes to it. You can find the source code here.

Changes to the sample application

There are few changes I would like to point out before we continue.

Let’s get started

Again before continuing, I recommend you read though my previous article. It would set up the context and fill in the gaps present in this post.
Done! Good!

The first two steps remain same, download and install Docker Toolbox and create a Docker VM. If you have Windows 10 Pro or Enterprise, you may also give try to new Docker for Windows which has recently moved out of beta.

Change URLs in the code

You will have to change the URLs in your code to point to the new VM URL in the following places:

Publish the projects

Go to each project folder and run dotnet publish to publish in your desired folder.

dotnet publish -r debian.8-x64 -o <Path to output directory>

Changes to Dockerfile

I have already added Dockerfile to each of the project which should automatically get copied when you published each application in the previous step. Below I’ll explain the new Dockerfile.

FROM microsoft/dotnet:1.0.0-core

# Copy the app
COPY . /app

# Set the Working Directory
WORKDIR /app

# Configure the listening port to 80
ENV ASPNETCORE_URLS http://*:80

# Start the app
ENTRYPOINT dotnet <DLLNAME>

Build Image

This step remains as it was. Just run docker build -t <tag> . command in each output directory to create images.

Create the container

There are minor changes in the port mapping. Now kestrel in each container will listen on port 80, to which we bind host port as specified below

docker run -d -p 1941:80 --name idsrv-host idsrvhost
docker run -d -p 7017:80 --name client jsclient
docker run -d -p 3721:80 --name api sampleapi

That’s it.

These are all the changes required to run IdSrv 4 on docker targeting ASP.NET Core 1.0. Open the browser and go to the URL:PORT to view each of the site.

Leave a comment if you have any feedbacks.

comments powered by Disqus