0879.html 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Run Microsoft SQL Server Containerized in Docker</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Docker Made Easy,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Docker,Docker Container,Docker Host,Docker Installation Tutorial,Docker Made Simple,Docker Setup Tutorial,Docker Simplified,Docker Tutorial,Linux,Container,Containerization,SQL Server,MSSQL,Microsoft,Microsoft SQL Server,SQL Server Docker Container,SQL Server Management Studio,SSMS,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Run Microsoft SQL Server Containerized in Docker">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="01/31/2023 12:08:44 PM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Run Microsoft SQL Server Containerized in Docker</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>Installing Docker</h2>
  26. <ol>
  27. <li>Log into the Linux host and run the following commands in a terminal window
  28. <div class="codeBlock"># install prerequisites<br />
  29. sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y<br />
  30. # add docker gpg key<br />
  31. curl -fsSL https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release)/gpg | sudo apt-key add -<br />
  32. # add docker software repository<br />
  33. sudo add-apt-repository &quot;deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release) $(lsb_release -cs) stable&quot;<br />
  34. # install docker<br />
  35. sudo apt install docker-ce docker-compose containerd.io -y<br />
  36. # enable and start docker service<br />
  37. sudo systemctl enable docker &amp;&amp; sudo systemctl start docker<br />
  38. # add the current user to the docker group<br />
  39. sudo usermod -aG docker $USER<br />
  40. # reauthenticate for the new group membership to take effect<br />
  41. su - $USER</div>
  42. </li>
  43. </ol>
  44. <h2>Running MS SQL Server Container</h2>
  45. <ol>
  46. <li>Continue with the following commands in a terminal window
  47. <div class="codeBlock"># create working directory structure<br />
  48. mkdir ~/docker/mssql -p<br />
  49. # set owner of working directories<br />
  50. sudo chown &quot;$USER&quot;:&quot;$USER&quot; ~/docker -R<br />
  51. # allow the container to write to working directories<br />
  52. sudo chmod a+rwx -R ~/docker/mssql<br />
  53. # run the sql server docker container with persistent data<br />
  54. docker run -d --name mssql -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=&#39;Something$ecur3!&#39; -v ~/docker/mssql:/var/opt/mssql -p 1433:1433 --restart unless-stopped mcr.microsoft.com/mssql/server</div>
  55. </li>
  56. <li>At this point the SQL Server instance is running and can be interacted with via the sqlcmd command line interface
  57. <div class="codeBlock"># connect to the database via sqlcmd<br />
  58. # authenticate with the sa password set in the docker run command<br />
  59. docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -U SA<br />
  60. # output the SQL version<br />
  61. select @@version;<br />
  62. go</div>
  63. </li>
  64. </ol>
  65. <h2>Installing SQL Server Management Studio (optional)</h2>
  66. <p><em>NOTE: SQL Server Management Studio (SSMS) is currently only available for Windows hosts</em></p>
  67. <ol>
  68. <li>Log into a <span class="codeBlock">Microsoft</span> Windows host</li>
  69. <li>Download SQL Server Management Studio (SSMS) <a href="https://aka.ms/ssmsfullsetup" target="_blank">Download</a></li>
  70. <li>Navigate to the download directory and execute the downloaded SSMS Setup installer &gt; Click Install</li>
  71. <li>Once the installation completes, click Close</li>
  72. <li>Launch SSMS from the Start menu</li>
  73. <li>Complete the Connect to Server form with the following
  74. <p>Server type: Database Engine<br />
  75. Server name: &lt;%Docker host DNS or IP%&gt;<br />
  76. Authentication: SQL Server Authentication<br />
  77. Login: sa<br />
  78. Password: &lt;%MSSQL_SA_PASSWORD%&gt;</p>
  79. </li>
  80. </ol>
  81. <p>Documentation: <span><span class="codeBlock"><a href="https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-deployment" target="_blank">https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-deployment</a></span></span></p> </div>
  82. </div>
  83. </body>
  84. </html>