Docker Login Failed Using mssql-tools

260 views Asked by At

SSMS connects just fine. Run this code in PowerShell to duplicate the following error.

Any advice? Thanks!


Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..

docker pull mcr.microsoft.com/mssql/server
#Sql Server cmd Tools
docker pull mcr.microsoft.com/mssql-tools

#Set-up the Container:
docker run `
--name MSSQL-Latest `
-p 1433:1433 `
-e "ACCEPT_EULA=Y" `
-e "SA_PASSWORD=F00B4rB4z!" `
-v C:\Docker\SQL:/sql `
-d mcr.microsoft.com/mssql/server:latest


docker exec MSSQL-Latest /opt/mssql-tools/bin/sqlcmd `
-S localhost `
-U "SA" `
-P "SA_PASSWORD=F00B4rB4z!" ```
1

There are 1 answers

0
Mikolaj On

Just remove "SA_PASSWORD=" from the password you are trying to log in. You assigned "F00B4rB4z!" value to SA_PASSWORD env, not "SA_PASSWORD=F00B4rB4z!".

If you want to then execute some commands inside your container you could add options: --tty to allocate a pseudo-TTY and --interactive to keep STDIN open or just use -it for short.

The correct command should be:

docker exec -it MSSQL-Latest /opt/mssql-tools/bin/sqlcmd -S localhost -U "SA" -P "F00B4rB4z!"

Keep in mind that if you have earlier created any user with SA_PASSWORD, the SA_PASSWORD value being saved on your host disk in the path you specified in the bind mount volume. This bind mount will overrides your SA_PASSWORD in future created containers with the same bind mount volume.

Please, try to avoid using the latest tag. This approach may cause inaccuracies because you are not guaranteed which version of docker image you are currently using.