I have docker for windows installed on my machine. There is a console application targeting .net core 1.0.0 that tries to access a SQL Server database running on a different VM.
as in this answer
SQL Server instance string connection in Linux Docker
According to Saurabh Singh from Microsoft:
The Instance name support is available in v 1.1 of .Net Core. In v1.0 of .Net Core, Instance names are not supported on OS other than Windows.
So I don't think you can connect from .Net Core 1.0 running on Linux to an SQL Server using instance name.
Your choices seem to be:
don't use instance name wait for .Net Core 1.1 (planned for "Fall 2016") use pre-release version of .Net Core 1.1
Right click on your database, select 'Properties / Security / Server Authentication / SQL Server and Windows Authentication Mode' radio button. Restart the MS SQL service.
Example
"ConnectionStrings": {
"DefaultConnection": "Server=YourServerName;Database=YourDatabaseName;MultipleActiveResultSets=true;User Id=UserNameYouJustAdded;Password=PassordYouJustCreated"
},
Make sure you remove Trusted_Connection=True
.
My example Docker file
FROM microsoft/dotnet:nanoserver
ARG source=.
WORKDIR /app
EXPOSE 5000
EXPOSE 1433
ENV ASPNETCORE_URLS http://+:5000
COPY $source .
Running from the same location as the Docker file in an elevated PowerShell
dotnet publish
docker build bin\Debug\netcoreapp1.0\publish -t aspidserver
docker run -it aspidserver cmd
I wanted to run the container and see the output as it was running in PowerShell.
Once the container was up and running in the container at the command prompt I kicked off my application.
dotnet nameOfApplication.dll
If everything went to plan one should be up and running.
You can run a docker container with network settings set to host
. Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0.0.1) will refer to the docker host.
docker run --net=host ...
Then you should get the SQL Server database from inside the docker container as you do from your host.