Home DevOps Docker Resetting SA Password in MSSQL Server Docker

Resetting SA Password in MSSQL Server Docker

6521
Beautiful sailboats moored in the dock, amazing view of gorgeous white sail boats over mountains background in mild sunset light, luxury summer vacation in Marmaris, Turkey

Resetting SA Password in MSSQL Server Docker 2022

This was a bit tricky, so I thought I would share how this can actually be done. I found this difficult for several reasons. For one, SQL Server must be stopped for the script to work, because this is a container, it is not using systemctl, therefore terminating the SQL Server using a kill command results in the container exiting.

I figured out that stopping the container entirely, committing the container, and running a new container while overriding the entry point worked.

Commit Container

docker commit ${CONTAINER_ID} mrjb/mssql-test

Run Container

You will need to run a new instance of the committed container.

docker run -ti -u 0 --entrypoint=/bin/bash -v '/mnt/user/appdata/mssql':'/var/opt/mssql':'rw' mrjb/mssql-test

Running: mssql-conf set-sa-password

There are binaries that can be run to configure the SQL Server and they are located in this folder: cd /opt/mssql/bin

Running the command below will reset the password to whatever you put in the MSSQL_SA_PASSWORD environment variable.

MSSQL_SA_PASSWORD=${Password} /opt/mssql/bin/mssql-conf set-sa-password