sql-serverdockerdocker-swarmdocker-secrets

Docker: Set MSSQL password from a secret


I'm trying to set my MSSQL password's from a secret, but I don't know why it seems I'm not properly setting my secret as a password.

This is my YAML file:

version: '3.7'

services:
  notguiridb:
    image: mcr.microsoft.com/mssql/server:2019-latest
    environment:
      ACCEPT_EULA: "Y"
      MSSQL_SA_PASSWORD_FILE: /run/secrets/mysecret4
    secrets:
      - source: mysecret4
        target: mysecret4

secrets:
  mysecret4:
    external: true

Then I checked that the secret was the one I expected, but even doing that it says the login failed, so I suspect the environment variable MSSQL_SA_PASSWORD_FILE does not really work.

$ docker exec -it 5fd bash
$ mssql@5fd8471a22c4:/$ cat /run/secrets/mysecret4
"Pa55W0rd!1234*"

$ docker exec -it 5fd /opt/mssql-tools/bin/sqlcmd -U sa -P Pa55w0rd!1234*
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'sa'..
$ docker exec -it 5fd /opt/mssql-tools/bin/sqlcmd -U sa -P "Pa55w0rd!1234*"
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'sa'..

Solution

  • $ mssql@5fd8471a22c4:/$ cat /run/secrets/mysecret4
    "Pa55W0rd!1234*"
    

    Remove the surrounding quotes in the file. They will be stripped when you present a double-quoted string in the command.