<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server container Tips &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/sql-server-container-tips/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Mon, 12 Oct 2026 06:56:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>How to Build Your First SQL Server Container on Windows Server 2016</title>
		<link>https://www.bestdevops.com/tips-on-how-to-build-your-first-sql-server-container/</link>
					<comments>https://www.bestdevops.com/tips-on-how-to-build-your-first-sql-server-container/#respond</comments>
		
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Wed, 01 Mar 2017 05:58:52 +0000</pubDate>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[DevOps Tools]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server container]]></category>
		<category><![CDATA[SQL Server container Tips]]></category>
		<category><![CDATA[SQL Server container Tutorials]]></category>
		<guid isPermaLink="false">http://www.bestdevops.com/?p=834</guid>

					<description><![CDATA[A step-by-step guide to enabling Windows containers, pulling the SQL Server Express Docker image, running and managing containers, mounting persistent storage, and connecting via SQLCMD and SSMS.]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Containers offer a lightweight, fast alternative to full virtual machines for running SQL Server. Because they virtualize at the operating system level rather than the hardware level, you can run far more containers than VMs on a single host. They are also stateless by default, which makes them ideal for development, testing, and scenarios where you need to spin up a SQL Server instance quickly without waiting for a full installation.</p>



<p class="wp-block-paragraph">This guide walks through the end-to-end process of creating and managing a SQL Server container on Windows Server 2016 using Docker and Microsoft&#8217;s prebuilt SQL Server Express image. The same principles apply when working with the Developer Edition image or when building custom images for Standard and Enterprise editions.</p>



<h2 class="wp-block-heading">Why Run SQL Server in a Container?</h2>



<ul class="wp-block-list">
<li><strong>Speed:</strong> Containers start in seconds, eliminating lengthy SQL Server installation processes.</li>
<li><strong>Density:</strong> More containers than VMs can run on the same host hardware.</li>
<li><strong>Isolation:</strong> Containers isolate application workloads, which is useful in multi-tenant architectures.</li>
<li><strong>Disposability:</strong> Containers can be cloned, stopped, and deleted instantly, making them ideal for CI/CD pipelines and test environments.</li>
<li><strong>Persistence with volumes:</strong> By mounting host volumes, you can persist database files across container lifecycles.</li>
</ul>



<h2 class="wp-block-heading">Enabling Containers in Windows Server 2016</h2>



<p class="wp-block-paragraph">Before running any container, you must enable the Containers feature in Windows Server 2016:</p>



<ol class="wp-block-list">
<li>Open <strong>Server Manager</strong>.</li>
<li>Click <strong>Manage</strong> and select <strong>Add Roles and Features</strong>.</li>
<li>Click through the wizard until you reach the <strong>Features</strong> page.</li>
<li>Check the <strong>Containers</strong> checkbox and click <strong>Next</strong>.</li>
<li>Click <strong>Install</strong> and allow the process to complete (typically a few minutes).</li>
<li>Restart the server when prompted.</li>
</ol>



<p class="wp-block-paragraph">After the restart, install Docker using an elevated PowerShell prompt:</p>


<pre class="wp-block-code"><span><code class="hljs">Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider</code></span></pre>


<p class="wp-block-paragraph">A second reboot is required after installing Docker. Once the system is back up, verify the installation:</p>


<pre class="wp-block-code"><span><code class="hljs">docker version</code></span></pre>


<h2 class="wp-block-heading">Pulling the SQL Server Express Image</h2>



<p class="wp-block-paragraph">A Docker <em>image</em> is a read-only template that includes the operating system layers and application binaries. A running instance of an image is called a <em>container</em>. Microsoft publishes a prebuilt SQL Server 2016 Express image that bundles Windows Server Core and SQL Server Express together.</p>



<p class="wp-block-paragraph">Pull the image with the following command (note: the download is large because it includes the full Windows Server Core layer):</p>


<pre class="wp-block-code"><span><code class="hljs">docker pull microsoft/mssql-server-windows-express</code></span></pre>


<p class="wp-block-paragraph">After the pull completes, list your locally available images to confirm:</p>


<pre class="wp-block-code"><span><code class="hljs">docker images</code></span></pre>


<p class="wp-block-paragraph">You should see <code>microsoft/mssql-server-windows-express</code> in the output, along with its image ID and tag.</p>



<h2 class="wp-block-heading">Running and Stopping a SQL Server Container</h2>



<h3 class="wp-block-heading">Starting the Container</h3>



<p class="wp-block-paragraph">Use <code>docker run</code> to launch a SQL Server container:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">docker run -d -p <span class="hljs-number">1433</span>:<span class="hljs-number">1433</span> \
  -e sa_password=TempPa550wd<span class="hljs-comment"># \</span>
  -e ACCEPT_EULA=Y \
  microsoft/mssql-server-windows-express</code></span></pre>


<p class="wp-block-paragraph">Key parameters explained:</p>



<ul class="wp-block-list">
<li><code>-d</code> — Detached mode; the container runs in the background.</li>
<li><code>-p 1433:1433</code> — Maps TCP port 1433 on the host to port 1433 inside the container. Incoming traffic on the host port is forwarded to the container.</li>
<li><code>-e sa_password</code> — Sets the SQL Server <code>sa</code> (system administrator) password. The value must meet Windows password complexity requirements.</li>
<li><code>-e ACCEPT_EULA=Y</code> — Required to accept Microsoft&#8217;s End User License Agreement for SQL Server.</li>
</ul>



<p class="wp-block-paragraph">Confirm the container is running:</p>


<pre class="wp-block-code"><span><code class="hljs">docker ps</code></span></pre>


<p class="wp-block-paragraph">The output lists all running containers, including the container ID, image name, and uptime.</p>



<h3 class="wp-block-heading">Stopping and Removing a Container</h3>



<p class="wp-block-paragraph">Docker provides several commands to dispose of containers. You only need the first three characters of the container ID as a unique shorthand:</p>



<ul class="wp-block-list">
<li><code>docker stop &lt;id&gt;</code> — Sends a graceful stop signal; Docker force-kills after a 10-second timeout.</li>
<li><code>docker kill &lt;id&gt;</code> — Immediately terminates the container without a graceful shutdown.</li>
<li><code>docker rm &lt;id&gt;</code> — Removes a stopped container. Add <code>-f</code> to force-kill and remove in one step.</li>
</ul>



<p class="wp-block-paragraph">Example (assuming the container ID begins with <code>98c</code>):</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Stop the container gracefully</span>
docker stop <span class="hljs-number">98</span>c

<span class="hljs-comment"># Then remove it</span>
docker rm <span class="hljs-number">98</span>c</code></span></pre>


<h2 class="wp-block-heading">Attaching Databases to a Container</h2>



<p class="wp-block-paragraph">Containers do not have persistent storage by default — all data written inside a container is lost when it is removed. To persist database files, mount a host directory as a volume using the <code>-v</code> flag, and attach an existing database using the <code>attach_dbs</code> environment variable.</p>



<p class="wp-block-paragraph">The following example mounts the host directory <code>C:	emp</code> into the container and attaches an existing SQL Server database whose <code>.mdf</code> and <code>.ldf</code> files reside there:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">docker run -d -p <span class="hljs-number">1433</span>:<span class="hljs-number">1433</span> \
  -e sa_password=TempPa550wd<span class="hljs-comment"># \</span>
  -e ACCEPT_EULA=Y \
  -v C:/temp/:C:/temp/ \
  -e attach_dbs=<span class="hljs-string">"&#91;{'dbName':'EditorialDb','dbFiles':&#91;'C:\\temp\\editorialdb.mdf','C:\\temp\\editorialdb_log.ldf']}]"</span> \
  microsoft/mssql-server-windows-express</code></span></pre>


<p class="wp-block-paragraph">Key parameters explained:</p>



<ul class="wp-block-list">
<li><code>-v C:/temp/:C:/temp/</code> — Mounts the host path <code>C:\temp</code> into the container at the same path. Note the Linux-style forward-slash convention required by Docker.</li>
<li><code>attach_dbs</code> — A JSON-formatted environment variable that specifies the database name and the full paths to its data (<code>.mdf</code>) and log (<code>.ldf</code>) files as seen from inside the container.</li>
</ul>



<p class="wp-block-paragraph">When the container is later removed, any changes made to the database files on the mounted volume are preserved. However, configuration changes made <em>inside</em> the container — such as enabling accounts, changing passwords, or modifying server settings — are discarded unless you rebuild the image to include them.</p>



<h2 class="wp-block-heading">Connecting to the SQL Server Container</h2>



<h3 class="wp-block-heading">Using SQLCMD from Inside the Container</h3>



<p class="wp-block-paragraph">Use <code>docker exec</code> to launch an interactive SQLCMD session directly inside the container. Replace <code>5e9</code> with the first three characters of your container ID:</p>


<pre class="wp-block-code"><span><code class="hljs">docker exec -it 5e9 sqlcmd -S.</code></span></pre>


<p class="wp-block-paragraph">The <code>-it</code> flag creates an interactive terminal session. SQLCMD uses Windows authentication to connect to the local SQL Server instance inside the container. Once connected, you can run any supported T-SQL statement.</p>




<p class="wp-block-paragraph"><strong>Note:</strong> The <code>sa</code> account may be disabled in the SQL Server Express image by default. If you need to connect via SQL Server authentication, enable the <code>sa</code> account first using a SQLCMD session with Windows authentication before attempting to connect from external tools.</p>




<h3 class="wp-block-heading">Using SQL Server Management Studio (SSMS)</h3>



<p class="wp-block-paragraph">To connect from SQL Server Management Studio running on the host or another networked machine, you need the container&#8217;s IP address. Retrieve it with <code>docker inspect</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">docker inspect -f <span class="hljs-string">"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"</span> <span class="hljs-number">5e9</span></code></span></pre>


<p class="wp-block-paragraph">In SSMS, open a new connection and enter the container&#8217;s IP address followed by the SQL Server port (for example, <code>172.21.0.2,1433</code>). Select <strong>SQL Server Authentication</strong> and supply the <code>sa</code> credentials you set when running the container.</p>



<p class="wp-block-paragraph">Once connected, the containerized SQL Server instance behaves identically to any other SQL Server instance. You can browse databases, run queries, manage objects, and use all standard SSMS features.</p>



<h3 class="wp-block-heading">Connecting from Another Networked System</h3>



<p class="wp-block-paragraph">To reach the container from a different machine on the network, connect to the <em>host server&#8217;s</em> IP address (not the container&#8217;s internal IP) on the port you mapped with <code>-p</code>. For example, if the host IP is <code>192.168.1.100</code> and you mapped port 1433, use <code>192.168.1.100,1433</code> as the server name in SSMS.</p>



<h2 class="wp-block-heading">Summary</h2>



<p class="wp-block-paragraph">Running SQL Server in a Docker container on Windows Server 2016 is straightforward once you understand the core workflow:</p>



<ol class="wp-block-list">
<li>Enable the <strong>Containers</strong> feature in Windows Server 2016 and install Docker via PowerShell.</li>
<li>Pull the prebuilt <code>microsoft/mssql-server-windows-express</code> image.</li>
<li>Use <code>docker run</code> with appropriate port mappings, environment variables, and volume mounts to launch a configured SQL Server instance.</li>
<li>Attach existing databases via the <code>attach_dbs</code> environment variable and a mounted host volume to ensure data persistence.</li>
<li>Connect interactively using <code>docker exec</code> and SQLCMD, or remotely using SSMS with SQL Server authentication.</li>
</ol>



<p class="wp-block-paragraph">The stateless nature of containers means that configuration changes inside the container are ephemeral, but your database files stored on a mounted volume remain intact across container restarts and replacements. This pattern is well-suited to dev/test workflows, CI pipelines, and high-density database hosting scenarios.</p>



<p class="wp-block-paragraph"><em>Original source article: TechTarget</em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/tips-on-how-to-build-your-first-sql-server-container/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
