-1

I have Windows10, installed SQL Server sql2019, i.e. my-machine\sql2019. Also, I have run a SQL Server 2019 Docker on the same machine as described in the MS doc:

>docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest

The questions are:

  1. How to run Docker with named SQL Server instance ?
  2. How to connect to the SQL server in Docker?
ZedZip
  • 5,794
  • 15
  • 66
  • 119
  • *"How to run Docker with named SQL Server instance?"* You can't. Named instances are *only* supported on Windows. – Thom A Jan 04 '22 at 11:59
  • Please read: [Can I ask only one question per post?](https://meta.stackexchange.com/questions/222735/can-i-ask-only-one-question-per-post) – Turing85 Jan 04 '22 at 12:00
  • Have you read the documentation [Deploy and **connect to** SQL Server Docker containers](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-deployment?view=sql-server-ver15&pivots=cs1-powershell)? – Thom A Jan 04 '22 at 12:00
  • @Larnu : ok, but I have Windows 10 OS + windows based docker – ZedZip Jan 04 '22 at 12:01
  • 1
    Windows based Docker Containers are no longer supported, @ZedZip . [Update- Beta program for SQL Server on Windows container is suspended.](https://techcommunity.microsoft.com/t5/sql-server-blog/update-beta-program-for-sql-server-on-windows-container-is/ba-p/2516639) – Thom A Jan 04 '22 at 12:04
  • @larnu ok, in any case: how can I connect SSMS to the SQL Server in Docker? – ZedZip Jan 04 '22 at 12:05
  • Just like you normally would. Put the host name in (I assume `localhost`) and if needed the port that you have mapped the service running within docker to on the container's host. – Thom A Jan 04 '22 at 12:08
  • ok, it is the same machine: SQL Server 2019 installed and Docker+SQL Server 2019 run. – ZedZip Jan 04 '22 at 12:10
  • @ZedZip. `mcr.microsoft.com/mssql/server:2019-latest` is a Linux docker image. Rather than named instance, just expose a different port for each container (e.g. `-p 12345:1433`). – Dan Guzman Jan 04 '22 at 12:23
  • I do: PS H:\_Docker> docker run --network=bridge --name sql19 -h sql19 -it --rm -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=sql19pwd" - p 10433:1433 -d mcr.microsoft.com/mssql/server:2019-latest and then in SSMS on the same machine: localhost:10433, sa, sql19pwd - cannot connect. – ZedZip Jan 04 '22 at 12:28
  • 1
    Use a comma instead of colon to separate the host and port: `localhost,10433` – Dan Guzman Jan 04 '22 at 12:42
  • @DanGuzman : I try "localhost, 10433" and "127.0.0.1,10433" - SSMS cannot find the docker SQL Server. May be need to run the docker with any additional parameters? – ZedZip Jan 04 '22 at 12:48
  • And if you really made your password `sql19pwd` I would check that the container is still running (`docker ps`) and if not you should see why using `docker logs sql19`. You need a more complex password or SQL Server won't run. – Aaron Bertrand Jan 04 '22 at 13:22
  • @AaronBertrand you are right about password!!!!! Please write your comment as an answer I'll mark it – ZedZip Jan 04 '22 at 13:32

1 Answers1

1
  1. No, you can't have a named instance. If you need multiple containers, you can just use different ports. This was addressed in another question here:

  2. Your password sql19pwd is too weak. SQL Server will try to start, and then shut down. You can confirm this using docker logs <container name>. This was also addressed in a roundabout way here:

In your case:

docker logs sql19

Will yield, somewhere toward the end:

ERROR: Unable to set system administrator password: Password validation failed. The password does not meet SQL Server password policy requirements because it is not complex enough. The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols..

If you try a more complex but shorter password, it would be:

ERROR: Unable to set system administrator password: Password validation failed. The password does not meet SQL Server password policy requirements because it is too short. The password must be at least 8 characters..

I've been using mnemonics for Docker container passwords, but also trying to avoid characters like # and $ which can have special meaning. My favorite recently when using Azure SQL Edge is 3dg3Y0urB3ts.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490