cannot connect to localdb from docker container

Viewed 589

I have asp.net core web API project with entityframework ORM connecting to localdb. API works fine if I publish it and run locally. But if I move the published code to a linux container, the API is up and running but it cannot create localdb connection throwing the following error.

System.PlatformNotSupportedException: LocalDB is not supported on this platform.

My DokerFile looks like this:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY bin/Release/netcoreapp2.2/publish .
FROM base AS final
WORKDIR /app
ENTRYPOINT ["dotnet","MyWebApi.dll"]

Am I missing anything related to mssql. I am very new to docker stuff.

1 Answers

LocalDB isn't supported to run on Linux. Despite you can run it on your Win PC, but on Docker you run with Linux OS. At this time, Microsoft didn't support to bring LocalDB outside Windows. So you need to change LocalDB to SqlLite if you want to run it on Docker.

It is still one solution to help you run LocalDB with Docker by calling database on Host. This is the article to help you:

https://nickjanetakis.com/blog/docker-tip-35-connect-to-a-database-running-on-your-docker-host

Related