8

I'm trying to convert a service (IdentityServer 4 v2) that is a .Net Core 2.0 application to run on Docker for Windows. This is on a dev workstation only. I did the standard Visual Studio 2017 "Add Docker Support" to the existing Net Core 2.0 service. The service starts up fine, but fails due to these issues:

  1. The service is looking for a certificate installed on the local host machine. Running in docker it doesn't see this cert.
  2. The service is using DNS from the host machine etc/Hosts file to find our database server. The service running on Docker doesn't see the host machine DNS.

I attempted to set the network_mode in docker compose to "host" but that failed to build. What is the suggested way to set up such an environment?

The runtime is setup using docker compose, and the default compose and the configuration is very simple:

version: '3'

services:
  identity.server:
    image: identity.server
    ports:
      - "8100:8100"
    build:
      context: ./src/Identity.Server
      dockerfile: Dockerfile

The referenced dockerfile:

FROM microsoft/dotnet:2.0-runtime
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Identity.Server.dll"]

I have read the following answer, but it doesn't appear to work inside of .Net itself: https://devops.stackexchange.com/questions/1501/configure-docker-to-use-ssl-for-a-private-registry-on-windows-10?newreg=0d065d6c37214be4bd1f02a45e1248ba

We are accessing the cert like this and it just comes back null. It is found if the service is run outside of Docker.

var cert = X509.LocalMachine.CertificateAuthority.Thumbprint
.Find(settings.CertificateThumbprint).FirstOrDefault();
swannee
  • 3,346
  • 2
  • 24
  • 40

1 Answers1

0

Whole point of using docker is to separate container resources from other containers and host itself. From application POV, LocalMachine you're calling is not your host, but the "container", so everything works as intended.

I assume you don't want to put crt files inside image, which is very wise.

To make it work, place crt files in some folder and then mount that dir using docker volumes to the container or if you use docker in swarm, use docker secrets.

Miq
  • 3,931
  • 2
  • 18
  • 32