question

AnirbanGoswami-8125 avatar image
0 Votes"
AnirbanGoswami-8125 asked AnirbanGoswami-8125 commented

how can pass local DB 'ConnectionStrings' as environment variable at docker run command

Hi All,

I have a restful api app and it depends on a sql db (sql server 2012-express). Restful Api app picks all colours related data from sql-db tables.The restful api made at dotnetcore 2.2 and define sql-db connection at 'appsettings.json' as below ..

{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "
",
"ConnectionStrings": "data source= xxx,1433;Initial Catalog=ColoursDB;Integrated Security=True;ConnectRetryCount=0"
*
}

I am using 'Microsoft.EntityFrameworkCore' ORM of version 1.0.1 for sql db data retrieving..
Locally , running api , it fetches colour data from sql-DB..but when i did linux container as below command at windows -powershell and passing 'ConnectionStrings' as environment variable ..Api container gave an exception
For Build api-> $ docker build -t colourapiandsql:v1 -f Dockerfile .
For Run api -> $ docker run -d -p 8080:80 --name api01 -e ConnectionStrings="data source=xxx,1433;Initial Catalog=ColoursDB;Integrated Security=True;" colourapiandsql:v1

Api container is created but it gave an exception as below
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)".

Can you pls help me or guide me on how i can pass local DB 'ConnectionStrings' as environment variable at docker run command?

Many Thanks,



dotnet-ad
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cheong00 avatar image
0 Votes"
cheong00 answered AnirbanGoswami-8125 commented

You may want to check how to assign environment variables with semicolon in bash.

Remember, in *nix environment, semicolon carries special function as command separator.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you @cheong00 for replay.

I am looking on how can i pass a local sql-DB connection to a linux container api app by using as an environment variable as below
$ docker run -d -p 8080:80 --name api01 -e ConnectionStrings="data source=xxx,1433;Initial Catalog=ColoursDB;Integrated Security=True;" colourapiandsql:v1

I am using windows 10 pro with docker host (Server: Docker Engine - Community :- OS/Arch: linux/amd64 , Client: Docker Engine - Community :- OS/Arch: windows/amd64) with powershell.

Thanks,

0 Votes 0 ·

Changed and tried again .I looked into api container logs , error is coming as above.
I also found below reference thread for 'mcr.microsoft.com/mssql/server:2017-CU11-ubuntu' or 'mcr.microsoft.com/mssql/server:2017-latest' and it is saying that for Windows 10 Pro 1809+ as host , it gives a fatal error and possible not able to connect with another container.. or mounting purpose
https://github.com/microsoft/mssql-docker/issues/441

i am using host as win 10- Pro , Version 10.0.18362 -Build 18362 and docker-desktop,version:2.3.0.4(46911)-Engine:19.03.12 that why.. containers r creating successfully at OS/Arch: linux/amd64 environment but not able to connect with DB container.

Thank you very much to everybody who helped me a lots and understanding the real root cause.

Thanks,

0 Votes 0 ·