0

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.

Persei
  • 109
  • 2
  • 9

2 Answers2

3

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.

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • I update my question, I read these links and base my command on it but I get an error. – Persei May 04 '20 at 08:45
  • that seems because of multiple quotes in the environment variable, try to use escape character, – Adiii May 04 '20 at 08:47
  • Sorry, but the same `repository name` issue. – Persei May 04 '20 at 08:58
  • the command: `docker run -it -p 8888:80 dockerconfiguration -e "ConnectionStrings:DefaultConnection"="testsqlstring"` In link from stackoverflow, which you have in answer has: in first the repository name, second -e parametre because the **dockerconfiguration** is repo - name. – Persei May 04 '20 at 09:41
  • I do not think its repository name issue, just try to remove the `env` and then check does it throwing the same error – Adiii May 04 '20 at 10:08
  • also the command you have posted missing docker image name which is `qulix/admin`. so you can try `docker run -it --rm qulix/admin` and you will not experience error again – Adiii May 04 '20 at 10:09
  • But the issue with ConnectionString, not with repo-name, I just try to find the solution ( not a new error) and I a bit confusing because in a link (which you attached) write one order and it doesn't replace the connection string and your variant which gave me an error of repo name has another order because docker thinks this is repo-name, not the env. variable. In a question, I posted the name of a repository (before the -e tag) – Persei May 04 '20 at 10:29
0

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

Persei
  • 109
  • 2
  • 9