Persei
Persei

Reputation: 109

Why ConnectionString doesn't override when I send it in docker run command?

Can anyone help with the next issue:

In My application (Asp Net Core 3.1) I have the next connection string enter image description here

I should create some containers, which have different connection strings but the same image.

I wrote next docker run command (windows server) :

docker run --rm --name admin -it -d -p 8080:8080 qulix/admin -e "ConnectionString:MSSQL"="Server=<IP adress>;Database=BasketballDb;User Id=user;Password=123456;Trust_connection=false"

and connection string didn't change. I don't understand why but I start to read about environment variables but I don't correctly understand how it should help me.

Update

If I change a location it read it as the image name and get the next error enter image description here

C:\Program Files\Docker\Docker\resources\bin\docker.exe: invalid reference format: repository name must be lowercase.

Upvotes: 0

Views: 2225

Answers (2)

Persei
Persei

Reputation: 109

My solution was (in windows docker server) next line:

docker run --rm --name stat -it -d -p 8090:8080 -e ConnectionStrings:MSSQL="Server=<IP Adress>;Database=Basketball_stat;User Id=user;Password=123456;" admin

where

ConnectionStrings:MSSQL should be without any quotes

"Server=<IP Adress>;Database=Basketball_stat;User Id=user;Password=123456;" with quotes(double or single)

admin is the name of repository

Upvotes: 0

Adiii
Adiii

Reputation: 59936

Anything passes after image name in docker run command it considers as a parameter to entrypoint.

so try to rearrange the docker run command.

docker run --rm -e "ConnectionString:MSSQL\"=\"Server=<IP adress>;Database=BasketballDb;User Id=user;Password=123456;Trust_connection=false" qulix/admin

Also I am not sure your code part, you can look into this

asp.net core override connection strings via ENV variables

app-secrets aspnetcore-3.1

As consuming environment variable is something that depends on the codebase or framework.

Upvotes: 3

Related Questions