I had created a SQL Server docker container instance previously and was able to successfully log in. I removed that image and was migrating the code from a docker run command into a docker-compose with a backed Dockerfile.
I have the ENV MSSQL_SA_PASSWORD set in the dockerfile but, now, when I try and log in, it gives me an error: Login failed for user 'sa'". It seems like it is caching it somewhere and I no longer remember what that password was.
How do I remedy this and have the container only use the password set in the Dockerfile?
FROM mcr.microsoft.com/mssql/server:2022-latest
COPY source/database/scripts /usr/src/app
ENV MSSQL_SA_PASSWORD "MyPassword1"
ENV ACCEPT_EULA Y
# Run SQL Server process
ENTRYPOINT [ "/opt/mssql/bin/sqlservr" ]
Thanks
The three most common issues with the sa
password in Docker:
The command used SA_PASSWORD
instead of MSSQL_SA_PASSWORD
. The latter is the correct argument, Microsoft just likes to keep us on our toes.
It's not complex enough (see rules here and here) - though in your case you would have had trouble starting the container at all.
It is complex enough, but it contains special characters that require escaping. When you pass via a string the character $
at the command line, for example, you need to escape it ($$
). Or just avoid non-alphanumeric characters that are "special." Underscore can be a good alternative to $
. I talk about this in the section "How to create a password" here: