Login fails for SA sql server linux docker

Viewed 13898

I try to use sql server on docker, linux. I start the container like this:

docker run -d -p 1433:1433 -e sa_password="12345qwerASDF" -e ACCEPT_EULA=Y --name sql-server --hostname sql-server  microsoft/mssql-server-linux:2017-latest

When I try to connect, all I get is "Login failed for user 'sa'"

Tried with different password, with and without double and single quotes...

8 Answers

Finally I got it to work:

docker run --name sqlserver --hostname sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest 

I guess it should be MSSQL_SA_PASSWORD and not SA_PASSWORD

The documentation isn't clear in that part...

Your password 12345qwerASDF doesn't meet complexity requirements. Try adding a non-alphanumeric characters such as exclamation point (!).

To check for errors, run: docker logs ID (where ID is container ID from docker ps).

For docker-compose file i was facing problem with sa user login failed i fix it by adding depends_on: - db

here's my full version of docker-compose file

version: '3.1'
services: 
 colour-api: 
  build: .
  environment:
   DBServer: "ms-sql-server"
  ports:
  - "8080:80" 
  depends_on:
   - ms-sql-server
 ms-sql-server:
  image: mcr.microsoft.com/mssql/server
  environment:
   ACCEPT_EULA: "Y"
   MSSQL_SA_PASSWORD: "Pa55w0rd2019" 
  ports: 
   - "1444:1433" 

Follow this link for more details

https://docs.docker.com/compose/aspnet-mssql-compose/

Try this :

docker run -e "ACCEPT_EULA=Y" -e "sa_password=12345qwerASDF" -p 1433:1433 --name sql-server --hostname sql-server -d microsoft/mssql-server-linux:2017-latest

IMPORTANT NOTE: If you are using PowerShell on Windows to run these commands use double quotes instead of single quotes.

Source : https://hub.docker.com/r/microsoft/mssql-server-linux/

I solved my problem with this notes

  1. In formal doc used SA_PASSWORD !!!, but MSSQL_SA_PASSWORD is true (Microsoft team, what are doing?!!!!)
  2. As a docker "[Configuration/Requirements for Microsoft SQL Server][1]" said: " A strong system administrator (SA) password: At least 8 characters including uppercase, lowercase letters, base-10 digits and/or non-alphanumeric symbols."
  3. In Linux, use single quote for define password .
  4. Be sure, before you run "docker run .." , the volume of "data" which you mount from host to container must be clean (if you have it!).

Here is a sample of “docker run” for creation Microsoft SQL Server container.

docker run  
-e ACCEPT_EULA=Y 
-e MSSQL_SA_PASSWORD='Mssql!Passw0rd' 
-e MSSQL_DATA_DIR=/var/opt/mssql/data  
-e MSSQL_PID='Developer' 
-e MSSQL_TCP_PORT=1433 
-p 1433:1433  
-v /var/opt/mssql/data:/var/opt/mssql/data  
-v /var/opt/mssql/log:/var/opt/mssql/log  
-v /var/opt/mssql/secrets:/var/opt/mssql/secrets 
--name mssql_2017 
-d mcr.microsoft.com/mssql/server:2017-latest

for checking an instance of SQL Server ...

docker exec -it mssql_2017 /bin/bash
cd /opt/mssql-tools/bin/
./sqlcmd -S localhost -U SA -P 'Mssql!Passw0rd'
select @@version
go

I hope this hints can help you.

The docker volume used for the mssql service could be corrupted.

In a docker setup using mcr.microsoft.com/mssql/server:2019-latest I have encountered a similar problem. Although I had no problem connecting to the server from a container built from the command line the issue persisted for the docker container.

Removing the volume and recreating the container did the trick.

docker run --name SQLServer -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=“Yourpassword” -e MSSQL_PID="Express" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest

Same thing happened to me but the problem was I had a windows desktop version of MSSQL and I forgot to stop the service before connecting to the docker version.

Related