{"id":9163,"date":"2021-10-05T22:06:00","date_gmt":"2021-10-05T20:06:00","guid":{"rendered":"https:\/\/www.fluentbytes.com\/?p=9163"},"modified":"2022-03-30T17:19:46","modified_gmt":"2022-03-30T15:19:46","slug":"how-to-fix-login-failed-for-sa-when-running-ms-sql-server-on-linux-in-a-docker-container","status":"publish","type":"post","link":"https:\/\/fluentbytes.com\/?p=9163","title":{"rendered":"How to Fix: Login failed for SA when running MS SQL Server on Linux in a Docker container"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>TLDR;\nIt seems the documentation on how to start the Linux based sql server container contains a bug! The documentation states you need to start the container using the following command-line:<\/p>\n<pre><code>docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d mcr.microsoft.com\/mssql\/server:2019-latest\n<\/code><\/pre>\n<p>But this is wrong, because it will not set the password for SA<\/p>\n<p>It took me hours to discover the environment variable they actually use to set the SA password is &#8216;MSSQL_SA_PASSWORD&#8217;<\/p>\n<p>So when you use the following command line it just works<\/p>\n<pre><code>docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d mcr.microsoft.com\/mssql\/server:2019-latest\n<\/code><\/pre>\n<p>Hopefully it will save you from pulling your hear out and also searching for hours. I filed this as a bug, hopefully the docs or the scripts are updated soon. <a href=\"https:\/\/github.com\/microsoft\/mssql-docker\/issues\/640\">Github Issue<\/a><\/p>\n<h2>Steps to reproduce:<\/h2>\n<ul>\n<li>Run the command-line as advertised in the documentation to start the container.<\/li>\n<li>Run a docker exec command to run a bash shell in the container interactively<\/li>\n<li>Run the following command:<\/li>\n<\/ul>\n<pre><code>\/opt\/mssql-tools\/bin\/sqlcmd -S localhost -U SA -P 'yourStrong(!)Password'\n<\/code><\/pre>\n<p>This will give you the following error:<\/p>\n<pre><code>Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..\n<\/code><\/pre>\n<p>Now remove the container and try again, but replace the -e &#8216;SA_PASSWORD=yourStrong(!)Password&#8217; with -e &#8216;MSSQL_SA_PASSWORD=yourStrong(!)Password&#8217;<\/p>\n<p>Try the same steps again, and voila, you are connected to the SQL server.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":9167,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"How to Fix: Login failed for SA when running MS SQL Server on Linux in a Docker container","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/fluentbytes.com\/wp-content\/uploads\/2020\/10\/Containers.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/posts\/9163"}],"collection":[{"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9163"}],"version-history":[{"count":3,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/posts\/9163\/revisions"}],"predecessor-version":[{"id":9166,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/posts\/9163\/revisions\/9166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=\/wp\/v2\/media\/9167"}],"wp:attachment":[{"href":"https:\/\/fluentbytes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fluentbytes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}