Docker + connect to host (localdb)

  docker, localdb

Is it possible to connect to SQL Server Express (localdb) from a container instance?

docker-compose sample connection string:

foo-api:
  image: foo-api
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ConnectionStrings:DefaultConnection=Server=host.docker.internalmssqllocaldb;Database=FooDB;MultipleActiveResultSets=true;User Id=foo;Password=Your_password123;        
    build:
      context: ../ms-foo/src/
      dockerfile: Dockerfile
    ports:
      - "6004:6004"

Running the app @ localhost wtih this config works just fine:

"ConnectionStrings": {
  "DefaultConnection": "Server=(localdb)mssqllocaldb;Database=FooDB;MultipleActiveResultSets=true;User Id=foo;Password=Your_password123;"
},

Is there some dns resolution I’m missing or does the instance need to be shared somehow?

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15#shared-instances-of-localdb?

Source: Docker Questions

LEAVE A COMMENT