connection string for sqlserver in Docker container

后端 未结 5 1671
無奈伤痛
無奈伤痛 2020-12-29 18:55

I\'m using Visual Studio 2017 for mac with dotnet Core and EF Core. After setting up the mssql image in Docker container , I was trying to add the connection string but thr

5条回答
  •  醉梦人生
    2020-12-29 19:38

    I had this problem today and I resolved it using a separate network (instead of using default "bridge" network).

    1. docker network create test_network

    2. docker container run -p 1433:1433 -d --name mssql -v mssql_data:/var/opt/mssql -e SA_PASSWORD=********** -e ACCEPT_EULA=Y --network=test_network microsoft/mssql-server-linux

    3. docker container run -p 5000:80 --rm -e ASPNETCORE_ENVIRONMENT=Development --name aspnetcore --network=test_network aspnetcore-image

    Also I have such connection string:

    Server=mssql;Database=master;User=sa;Password=**********;
    

    About previous answers regarding Connection String with IP address, it is not a good approach, because this address can be changed dynamically, it is better to use container names, as hostnames.

提交回复
热议问题