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

Anirban Goswami 256 Reputation points
2020-12-08T19:24:16.02+00:00

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,

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,356 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cheong00 3,471 Reputation points
    2020-12-09T02:15:11.173+00:00

    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.