<?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>Containers Archives - The SERO Group</title>
	<atom:link href="https://theserogroup.com/tag/containers/feed/" rel="self" type="application/rss+xml" />
	<link>https://theserogroup.com/tag/containers/</link>
	<description>SQL Servers Healthy, Secure, And Reliable</description>
	<lastBuildDate>Thu, 23 Jun 2022 20:43:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://theserogroup.com/wp-content/uploads/2024/07/cropped-Canister-only-1-32x32.png</url>
	<title>Containers Archives - The SERO Group</title>
	<link>https://theserogroup.com/tag/containers/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">121220030</site>	<item>
		<title>Use a Docker Container to Explore SQL Server 2022&#8217;s New Features</title>
		<link>https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/</link>
					<comments>https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/#comments</comments>
		
		<dc:creator><![CDATA[Joe Webb]]></dc:creator>
		<pubDate>Thu, 23 Jun 2022 20:43:27 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Containers]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[IT Manager]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[Sero]]></category>
		<category><![CDATA[Sero Group]]></category>
		<category><![CDATA[Serogroup]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Consultant]]></category>
		<category><![CDATA[SQL Events]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server Consultant]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<category><![CDATA[SQL Training]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[The Sero Group]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=4496</guid>

					<description><![CDATA[<p>There&#8217;s a lot of hype surrounding the next version of SQL Server. And for good reason. SQL Server 2022 is packed with some long awaited niceties, improvements, and enhancements. Here are a few of the SQL Server 2022&#8217;s new features we are excited about. Contained Availability Groups Enhancements to Availability Groups and Distributed Availability Groups&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/">Use a Docker Container to Explore SQL Server 2022&#8217;s New Features</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There&#8217;s a lot of hype surrounding the next version of SQL Server. And for good reason. SQL Server 2022 is packed with some long awaited niceties, improvements, and enhancements. Here are a few of the SQL Server 2022&#8217;s new features we are excited about.</p>



<ul class="wp-block-list"><li>Contained Availability Groups</li><li>Enhancements to Availability Groups and Distributed Availability Groups</li><li>Query Store enhancements, including being available on secondary replicas</li><li>Parameter Sensitive Plan (PSP) optimization</li><li>Ledger to help assure data hasn&#8217;t been tampered with</li></ul>



<p>You can learn more about SQL Server 2022 on the <a href="https://docs.microsoft.com/en-us/sql/sql-server/what-s-new-in-sql-server-2022?view=sql-server-ver16" target="_blank" rel="noreferrer noopener">What&#8217;s new in SQL Server 2022 &#8211; SQL Server | Microsoft Docs</a> site.</p>



<p>Now, how can you explore SQL Server 2022&#8217;s new features? </p>



<h2 class="wp-block-heading">Test Driving SQL Server 2022</h2>



<p>Containers are a great way to explore new versions of a product like SQL Server without having to actually install bits on your computer that you&#8217;ll later want to remove. Containers are lightweight, standalone, and have everything required to run SQL Server. There&#8217;s nothing to install directly on your host machine. And nothing to remove later, except, of course, the container and image file. But those won&#8217;t leave remnants of SQL Server in your registry or file system.</p>



<h3 class="wp-block-heading">Prerequisites </h3>



<p>To use SQL Server in a Docker container, you&#8217;ll need the <a href="https://www.docker.com/products/docker-desktop" target="_blank" rel="noreferrer noopener">Docker Desktop</a>. There are versions for most every desktop platform, including Windows, Mac, and Linux. In <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started with SQL Server in a Docker Container &#8211; The SERO Group</a>, I walk through the process of configuring Docker Desktop for a Windows 10 client. If you don&#8217;t already have the Docker Desktop installed, do that first. </p>



<h3 class="wp-block-heading">Pulling the SQL Server 2022 container image</h3>



<p>Once you have Docker Desktop in place, you can pull (download) the SQL Server 2022 image using the following command in the Windows command prompt.</p>



<pre class="wp-block-code"><code>docker pull mcr.microsoft.com/mssql/server:2022-latest</code></pre>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/pullsql2022.png"><img fetchpriority="high" decoding="async" width="690" height="335" src="https://theserogroup.com/wp-content/uploads/2022/06/pullsql2022.png" alt="pull sql server 2022 docker container" class="wp-image-4500" srcset="https://theserogroup.com/wp-content/uploads/2022/06/pullsql2022.png 690w, https://theserogroup.com/wp-content/uploads/2022/06/pullsql2022-300x146.png 300w" sizes="(max-width: 690px) 100vw, 690px" /></a></figure>



<h3 class="wp-block-heading">Starting the SQL Server 2022 container</h3>



<p>Once the pull has completed, you can create the container from the image using the following command.</p>



<pre class="wp-block-code"><code>docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=iO1$6sJ&amp;64YRCJAx" -p 1433:1433 --name sql2022ctp1 -d mcr.microsoft.com/mssql/server:2022-latest</code></pre>



<p>The ACCEPT_EULA parameter indicates that you agree to Microsoft’s End User Licensing Agreement. SA_PASSWORD parameter is where you set the sa password for this instance. You&#8217;ll want to replace iO1$6sJ&amp;64YRCJAx in the example above with a complex password of your choosing.</p>



<p>The -p parameter allows you to map a TCP port on the host environment to a port in the container. In this example, I’m mapping the default host environment port of 1433 to the container port of 1433.</p>



<p>Set the name for your container using the –name parameter. I’m naming this one sql2022ctp1.</p>



<p>And finally, the -d parameter is the name of the container image your want to run.</p>



<h3 class="wp-block-heading">Listing your containers</h3>



<p>You can use the following command to list all containers in your Docker environment.</p>



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



<p>You can see that this Docker environment has two SQL Server 2019 containers, sql2019 and sql2019a, along with our newly created container, sql2022ctp1. The sql2022ctp1 container is running. The other two are not.</p>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/dockerpsa.png"><img decoding="async" width="690" height="333" src="https://theserogroup.com/wp-content/uploads/2022/06/dockerpsa.png" alt="docker list sql server containers" class="wp-image-4503" srcset="https://theserogroup.com/wp-content/uploads/2022/06/dockerpsa.png 690w, https://theserogroup.com/wp-content/uploads/2022/06/dockerpsa-300x145.png 300w" sizes="(max-width: 690px) 100vw, 690px" /></a></figure>



<p>You can also see your containers in the Docker Desktop as shown below.</p>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/Screen-Shot-2022-06-23-at-10.44.18-AM.png"><img decoding="async" width="956" height="602" src="https://theserogroup.com/wp-content/uploads/2022/06/Screen-Shot-2022-06-23-at-10.44.18-AM.png" alt="docker desktop sqlserver 2022 ctp 1" class="wp-image-4501" srcset="https://theserogroup.com/wp-content/uploads/2022/06/Screen-Shot-2022-06-23-at-10.44.18-AM.png 956w, https://theserogroup.com/wp-content/uploads/2022/06/Screen-Shot-2022-06-23-at-10.44.18-AM-300x189.png 300w, https://theserogroup.com/wp-content/uploads/2022/06/Screen-Shot-2022-06-23-at-10.44.18-AM-768x484.png 768w" sizes="(max-width: 956px) 100vw, 956px" /></a></figure>



<h3 class="wp-block-heading">Querying the SQL Server 2022 instance</h3>



<p>Using Azure Data Studio or SQL Server Management Studio, you can connect to your new SQL Server 2022 instance and query as normal from your host operating system. For example, running the following query in Azure Data Studio will return the SQL Server Edition, Version, and Product Level.</p>



<pre class="wp-block-code"><code>SELECT  SERVERPROPERTY('Edition') AS SQLEdition,
        SERVERPROPERTY('ProductVersion') AS ProductVersion,
        SERVERPROPERTY('ProductLevel') AS ProductLevel;</code></pre>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/sql2022info1.png"><img loading="lazy" decoding="async" width="512" height="102" src="https://theserogroup.com/wp-content/uploads/2022/06/sql2022info1.png" alt="sql server 2022 info" class="wp-image-4504" srcset="https://theserogroup.com/wp-content/uploads/2022/06/sql2022info1.png 512w, https://theserogroup.com/wp-content/uploads/2022/06/sql2022info1-300x60.png 300w" sizes="auto, (max-width: 512px) 100vw, 512px" /></a></figure>



<p>You can use the following query to review information about the host operating system. </p>



<pre class="wp-block-code"><code>SELECT  host_platform, 
        host_distribution, 
        host_release
FROM    sys.dm_os_host_info;</code></pre>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/sqlserver2022hostinfo.png"><img loading="lazy" decoding="async" width="473" height="110" src="https://theserogroup.com/wp-content/uploads/2022/06/sqlserver2022hostinfo.png" alt="sql server container host information" class="wp-image-4505" srcset="https://theserogroup.com/wp-content/uploads/2022/06/sqlserver2022hostinfo.png 473w, https://theserogroup.com/wp-content/uploads/2022/06/sqlserver2022hostinfo-300x70.png 300w" sizes="auto, (max-width: 473px) 100vw, 473px" /></a></figure>



<h2 class="wp-block-heading">Exploring SQL Server 2022&#8217;s new features</h2>



<p>Now that you have a working SQL Server 2022 instance, you can begin exploring its new features. </p>



<p>For example, I&#8217;d like to better understand the new Parameter Sensitivity Plan (PSP) optimization enhancements. So, I restored a copy of the <a href="https://theserogroup.com/career-development/data-getcha-data-here/">BaseballData</a> database that I sometimes use for testing and demos. See <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started with SQL Server in a Docker Container &#8211; The SERO Group</a> for how to restore a backup to your container. </p>



<p>Next, I set the compatibility level of the BaseballData database to 160 and enable Query Store using the following t-sql commands.</p>



<pre class="wp-block-code"><code>ALTER DATABASE BaseballData  
SET COMPATIBILITY_LEVEL = 160;  

ALTER DATABASE BaseballData 
SET QUERY_STORE (QUERY_CAPTURE_MODE = auto);</code></pre>



<p>To verify that setting the compatibility level to 160 enabled  PSP optimization, I can run the following query.</p>



<pre class="wp-block-code"><code>SELECT name, value, is_value_default
FROM sys.database_scoped_configurations
WHERE name = 'PARAMETER_SENSITIVE_PLAN_OPTIMIZATION'</code></pre>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2022/06/pspoptimization.png"><img loading="lazy" decoding="async" width="499" height="107" src="https://theserogroup.com/wp-content/uploads/2022/06/pspoptimization.png" alt="sql server 2022 psp optimization" class="wp-image-4513" srcset="https://theserogroup.com/wp-content/uploads/2022/06/pspoptimization.png 499w, https://theserogroup.com/wp-content/uploads/2022/06/pspoptimization-300x64.png 300w" sizes="auto, (max-width: 499px) 100vw, 499px" /></a></figure>



<p>Now I can begin experimenting how PSP optimization affects my queries. For more information about PSP optimization, see <a href="https://docs.microsoft.com/en-us/sql/relational-databases/performance/parameter-sensitivity-plan-optimization?view=sql-server-ver16">Parameter Sensitivity Plan optimization &#8211; SQL Server | Microsoft Docs</a>. </p>



<h2 class="wp-block-heading">Stopping and starting your Docker container</h2>



<p>You can leave your container running all the time if you wish. However, if you like to stop it and start it again later, you can with the following command, where sql2022ctp1 is the name you gave to your container.</p>



<pre class="wp-block-code"><code>docker stop sql2022ctp1</code></pre>



<p>To start the container later, use the following.</p>



<pre class="wp-block-code"><code>docker start sql2022ctp1</code></pre>



<h2 class="wp-block-heading">Want to work with The SERO Group?</h2>



<p>Want to learn more about how SERO Group helps organizations take the guesswork out of managing their SQL Servers? It’s easy and there is no obligation.&nbsp;</p>



<p>Schedule a&nbsp;<a href="https://theserogroup.com/meet-with-joe-webb/">free 30-minute call</a>&nbsp;to see if our&nbsp;<a href="https://theserogroup.com/sql-health-check/">SQL Server Health Check</a>&nbsp;or one of our&nbsp;<a href="https://theserogroup.com/seroshield/">SEROShield</a>&nbsp;plans is right for you.</p>



<p><a href="https://theserogroup.com/meet-with-joe-webb" target="_blank" rel="noreferrer noopener">Schedule a call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/">Use a Docker Container to Explore SQL Server 2022&#8217;s New Features</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theserogroup.com/sql-server/use-a-docker-container-to-explore-sql-server-2022s-new-features/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4496</post-id>	</item>
		<item>
		<title>How to Use a Docker Host Folder for a SQL Server Database</title>
		<link>https://theserogroup.com/sql-server/how-to-use-a-docker-host-folder-for-a-sql-server-database/</link>
		
		<dc:creator><![CDATA[Joe Webb]]></dc:creator>
		<pubDate>Thu, 04 Nov 2021 17:39:32 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Containers]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[Sero]]></category>
		<category><![CDATA[Sero Group]]></category>
		<category><![CDATA[Serogroup]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Consultant]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<category><![CDATA[The Sero Group]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=4069</guid>

					<description><![CDATA[<p>In Getting Started with SQL Server in a Docker Container, I shared my SQL Server Docker container configuration. I described how to copy database backup files from your host to the container and then restore them in the container. That&#8217;s my usual approach. But what if you wanted the database to reside on the host&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/how-to-use-a-docker-host-folder-for-a-sql-server-database/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/how-to-use-a-docker-host-folder-for-a-sql-server-database/">How to Use a Docker Host Folder for a SQL Server Database</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started with SQL Server in a Docker Container</a>, I shared my SQL Server Docker container configuration. I described how to copy database backup files from your host to the container and then restore them in the container. That&#8217;s my usual approach. But what if you wanted the database to reside on the host instead of inside the Docker container? That would allow you to upgrade the container anytime you&#8217;d like and just run a few scripts to create users, attach databases, etc., afterward. That could be handy. So, let&#8217;s look at how to mount a Docker host folder in a containe for a SQL Server database. </p>



<h2 class="wp-block-heading">Using a Docker host folder for a SQL Server database</h2>



<p>For this example, I&#8217;m assuming you already have Docker Desktop installed and a SQL Server image available. If not, go back to the <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started</a> blog before continuing. As before, I&#8217;m using a Windows host computer and SQL Server 2019 in a Ubuntu Linux image. A similar approach will work for other hosts and images. </p>



<h3 class="wp-block-heading">Mounting a host folder to a Docker container</h3>



<p>To use a host folder from inside the Docker container, we must mount the folder when we first run the container. We do this by adding the -v parameter to the same docker run command we used before. </p>



<pre class="wp-block-code"><code>docker run -v C:\Users\JoeWebb\sql:/mnt/myhost/sql  -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=34r0TNhvgOde" -p 1433:1433 --name sql2019a -h sql2019 -d mcr.microsoft.com/mssql/server:2019-latest</code></pre>



<p>The -v parameter mounts the host volume to a folder in the container. In this example, I&#8217;m mounting the C:\Users\JoeWebb\sql folder to /mnt/myhost/sql in the container. If the mount location in the container doesn&#8217;t already exist, it will be created for you. </p>



<p>To briefly recap the other parameters, the ACCEPT_EULA parameter is where you agree to Microsoft’s End User Licensing Agreement, EULA. You set the sa password for the SQL instance using the SA_PASSWORD parameter. Map TCP ports using the -p parameter in the format &lt;host port>:&lt;container port>. Set the name for your container using the –name parameter and set your container’s hostname using the -h parameter. The -d parameter the image file to use.</p>



<p>Use the following command to verify that the container now has access to the mounted volume. The ls command list the contents of the mounted folder.</p>



<pre class="wp-block-code"><code>docker exec -it sql2019a ls -al /mnt/myhost/sql</code></pre>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2021/11/mountedfolderlist.png"><img loading="lazy" decoding="async" width="556" height="144" src="https://theserogroup.com/wp-content/uploads/2021/11/mountedfolderlist.png" alt="SQL folder list" class="wp-image-4073" srcset="https://theserogroup.com/wp-content/uploads/2021/11/mountedfolderlist.png 556w, https://theserogroup.com/wp-content/uploads/2021/11/mountedfolderlist-300x78.png 300w" sizes="auto, (max-width: 556px) 100vw, 556px" /></a></figure>



<p>The container can see host folder and lists its two subfolders, backup and data.</p>



<h3 class="wp-block-heading">Attaching a database in the mounted host folder</h3>



<p>Now that the host folder is available in your container, let&#8217;s attach the AdventureWorks2014 database to the sql2019a SQL Server instance. Open your favorite SQL Server query editor &#8211; Azure Data Studio, SQL Server Management Studio, Visual Studio Code, etc &#8211; and connect to the sql2019a instance. Run the following T-SQL command to attach the database. Notice that the data and log files are in the /mnt/myhost/sql/data folder. </p>



<pre class="wp-block-code"><code>CREATE DATABASE AdventureWorks2014 
ON
( NAME = AdventureWorks2014,
    FILENAME = '/mnt/myhost/sql/data/AdventureWorks2014_Data.mdf'), 
    (FILENAME = '/mnt/myhost/sql/data/AdventureWorks2014_Log.ldf')
    FOR ATTACH ;</code></pre>



<p>Now you have the AdventureWorks2014 database available in the sql2019a instance, yet the data and log files actually live outside the container in a Docker host folder.</p>



<h3 class="wp-block-heading">Restoring a database in the mounted folder.</h3>



<p>You can also restore a database to the mounted folder. However with the current images and Docker versions, there seems to be a slight issue doing this directly. When you try to restore a database to a mounted folder, you may receive an error like:</p>



<p><span class="has-inline-color has-vivid-red-color">Msg 3634, Level 16, State 1, Line 2<br>The operating system returned the error &#8216;2(The system cannot find the file specified.)&#8217; while attempting &#8216;RestoreContainer::ValidateTargetForCreation&#8217; on &#8216;/mnt/myhost/sql/data/Baseball_Data.mdf&#8217;. </span></p>



<p>See <a href="https://stackoverflow.com/questions/53623048/restore-database-in-docker-container">sql server &#8211; Restore database in docker container &#8211; Stack Overflow</a> for more information.</p>



<p>The work around for this is to first create an empty database on the mounted folder. Then restore the database from the backup file using WITH REPLACE. </p>



<p>Here a short script to restore the BaseballData database.</p>



<pre class="wp-block-code"><code>
CREATE DATABASE BaseballData 
ON
( NAME = BaseBallData_Data,
    FILENAME = '/mnt/myhost/sql/data/BaseBallData_data.mdf',
    SIZE = 10,
    MAXSIZE = 100,
    FILEGROWTH = 5 )
LOG ON
( NAME = BaseBallData_log,
    FILENAME = '/mnt/myhost/sql/data/BaseBallData_log.ldf',
    SIZE = 5MB,
    MAXSIZE = 100MB,
    FILEGROWTH = 5MB ) ;


GO

RESTORE DATABASE BaseBallData 
    FROM DISK='/mnt/myhost/sql/backup/BaseBallData.bak' 
    WITH REPLACE,
    MOVE 'LahmansBaseballDB' TO '/mnt/myhost/sql/data/BaseballData_data.mdf', 
    MOVE 'LahmansBaseballDB_log' TO '/mnt/myhost/sql/data/BaseballData_log.ldf';
</code></pre>



<p>Note: when you use the -v parameter to mount a folder in the container, Docker Desktop may warn you that performance could be an issue. You&#8217;ll certainly want to test to see if that&#8217;s the case for you. </p>



<h2 class="wp-block-heading">Want to work with The SERO Group?</h2>



<p>We bring reliability, performance, and security to companies that traditionally could not justify an experienced DBA on staff. It&#8217;s called SEROShield. Want to learn more? It’s easy and there is no obligation. </p>



<p><a href="https://calendly.com/joe_webb" target="_blank" rel="noreferrer noopener">Schedule a call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/how-to-use-a-docker-host-folder-for-a-sql-server-database/">How to Use a Docker Host Folder for a SQL Server Database</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4069</post-id>	</item>
		<item>
		<title>Getting Started with SQL Server in a Docker Container</title>
		<link>https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/</link>
					<comments>https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/#comments</comments>
		
		<dc:creator><![CDATA[Joe Webb]]></dc:creator>
		<pubDate>Wed, 20 Oct 2021 13:00:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Containers]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[IT Manager]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[Sero]]></category>
		<category><![CDATA[Sero Group]]></category>
		<category><![CDATA[Serogroup]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Consultant]]></category>
		<category><![CDATA[SQL Server Consultant]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<category><![CDATA[The Sero Group]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=3993</guid>

					<description><![CDATA[<p>You&#8217;ve probably heard of running SQL Server in a Docker container. The technology has been around for some years now. However it&#8217;s still unexplored territory for many. A SQL Server Docker container image is a lightweight and standalone package that includes everything needed to run SQL Server. It&#8217;s often used in DevOps as part of&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started with SQL Server in a Docker Container</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You&#8217;ve probably heard of running SQL Server in a Docker container. The technology has been around for some years now. However it&#8217;s still unexplored territory for many. </p>



<p>A SQL Server Docker container image is a lightweight and standalone package that includes everything needed to run SQL Server. It&#8217;s often used in DevOps as part of the Continuous Integration / Continuous Deployment (CI/CD) processes. Using containers, SQL Server systems can be quickly and easily configured and reconfigured programmatically for dev, test, QA, and demo environments.</p>



<h2 class="wp-block-heading">Using SQL Server in a Docker Container</h2>



<p>The first experience many of have with SQL Server in a Docker container is setting up a development or demo system on a laptop or desktop. The process can initially seem a bit foreign so let&#8217;s walk through it here.</p>



<h3 class="wp-block-heading">Install the Docker Engine</h3>



<p>The first step is installing the Docker Desktop. There are versions of the <a rel="noreferrer noopener" href="https://www.docker.com/products/docker-desktop" target="_blank">Docker Desktop</a> available for Windows, Mac, and Linux. Choose the one that&#8217;s right for you and download it. I&#8217;m installing on Windows 10 Enterprise in this example. </p>



<p>There are plenty of good how-tos on the internet for installing Docker. So, I won&#8217;t go into much detail here other than to highlight a couple of potential gotchas. </p>



<p>Once downloaded, run the Docker Desktop Installer.exe file. It may take several minutes to unpack and load everything it needs. </p>



<p>After the install program has completed, you&#8217;re prompted to restart your Windows computer. I frequently do not worry with restart messages. However, in this case, it is usually needed. If you launch the Docker Desktop app without a restart, you may get this Docker Desktop &#8211; Access denied message. A restart will typically resolve it. </p>



<figure class="wp-block-image size-full is-resized"><a href="https://theserogroup.com/wp-content/uploads/2021/10/DockerDesktopDenied.png"><img loading="lazy" decoding="async" src="https://theserogroup.com/wp-content/uploads/2021/10/DockerDesktopDenied.png" alt="Docker Desktop Access Denied message" class="wp-image-4003" width="359" height="146" srcset="https://theserogroup.com/wp-content/uploads/2021/10/DockerDesktopDenied.png 718w, https://theserogroup.com/wp-content/uploads/2021/10/DockerDesktopDenied-300x122.png 300w" sizes="auto, (max-width: 359px) 100vw, 359px" /></a></figure>



<p>Also, if your Docker Engine will not start, you may have to <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package" target="_blank">update the Linux kernel update package for WSL</a>. </p>



<h3 class="wp-block-heading">Pull the SQL Server Docker container image</h3>



<p>Once your Docker Engine is running, use the following Windows command to pull, or download, the latest SQL Server Docker container image. </p>



<pre class="wp-block-code"><code>docker pull mcr.microsoft.com/mssql/server:2019-latest</code></pre>



<figure class="wp-block-image size-large"><a href="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload.png"><img loading="lazy" decoding="async" width="1024" height="411" src="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload-1024x411.png" alt="Pull SQL Server Docker Image" class="wp-image-4007" srcset="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload-1024x411.png 1024w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload-300x120.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload-768x308.png 768w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerDownload.png 1276w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<h3 class="wp-block-heading">Run the SQL Server Docker container</h3>



<p>Now that we have Docker Desktop installed and the latest SQL Server image downloaded, it&#8217;s time to run the SQL Server Docker container. Use the following command in your command window. </p>



<pre class="wp-block-code"><code>docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=34r0TNhvgOde" -p 1433:1433 --name sql2019 -h sql2019 -d mcr.microsoft.com/mssql/server:2019-latest</code></pre>



<p>The ACCEPT_EULA parameter signifies that you agree to Microsoft&#8217;s End User Licensing Agreement. </p>



<p>SA_PASSWORD is where you set the sa password for this instance. Replace 34r0TNhvgOde in the example with a complex password of your choosing. </p>



<p>The -p parameter allows you to map a TCP port on the host environment to a port in the container. In this example, I&#8217;m mapping the default host environment port of 1433 to the container port of 1433. </p>



<p>Set the name for your container using the &#8211;name parameter. I&#8217;m naming this one sql2019.</p>



<p>Likewise define your container&#8217;s hostname using the -h parameter. </p>



<p>And finally, the -d parameter is the name of the container image your want to run.  </p>



<h3 class="wp-block-heading">Connecting to and querying the SQL Server Docker container</h3>



<p>You can connect to your new SQL Server in the Docker container as you would any other SQL Server instance. The image below show how I can connect my new sql2019 container instance using Azure Data Studio on my Windows desktop. </p>



<figure class="wp-block-image size-large"><a href="https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker.png"><img loading="lazy" decoding="async" width="1024" height="767" src="https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-1024x767.png" alt="Connecting to SQL Server using Azure Data Studio" class="wp-image-4010" srcset="https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-1024x767.png 1024w, https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-300x225.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-768x575.png 768w, https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-1536x1150.png 1536w, https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-2048x1533.png 2048w, https://theserogroup.com/wp-content/uploads/2021/10/ConnectingADSDocker-1443x1080.png 1443w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Once connected, you can query the instance. For example, I can run the following query to gather information about the SQL instance. </p>



<pre class="wp-block-code"><code>SELECT  SERVERPROPERTY('MachineName') AS MachineName,
        SERVERPROPERTY('ServerName') AS InstanceName,
        SERVERPROPERTY('Edition') AS SQLEdition,
        SERVERPROPERTY('ProductVersion') AS ProductVersion,
        SERVERPROPERTY('ProductLevel') AS ProductLevel;
SELECT  host_platform, 
        host_distribution, 
        host_release
FROM    sys.dm_os_host_info;</code></pre>



<figure class="wp-block-image size-large"><a href="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo.png"><img loading="lazy" decoding="async" width="1024" height="380" src="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo-1024x380.png" alt="Querying SQL Server Docker Container" class="wp-image-4013" srcset="https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo-1024x380.png 1024w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo-300x111.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo-768x285.png 768w, https://theserogroup.com/wp-content/uploads/2021/10/SQLDockerInfo.png 1472w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>In the results, you can see this Ubuntu Linux container is running SQL Server 2019 Developer Edition. </p>



<h2 class="wp-block-heading">Restoring a backup to your SQL Server Docker container</h2>



<p>Now that you have a working SQL Server instance, let&#8217;s restore a copy of our <a href="https://theserogroup.com/career-development/data-getcha-data-here/">BaseballData </a>database to it. </p>



<h3 class="wp-block-heading">Copy the backup file to the Docker container</h3>



<p>Create a backup folder in the container using the following Docker command. </p>



<pre class="wp-block-code"><code>docker exec -it sql2019 mkdir /var/opt/mssql/backup</code></pre>



<p>The exec parameter is used to execute commands inside the specified container. The -it parameter indicates that it will be an interactive terminal command.</p>



<p>Next, copy the SQL Server backup file to the newly created backup folder in the container using the Docker cp command. In this example, I’m copying the BaseballData.bak file from the present working directory on the host computer to the /var/opt/mssql/backup folder in the sql2019 container. </p>



<pre class="wp-block-code"><code>docker cp BaseballData.bak sql2019:/var/opt/mssql/backup</code></pre>



<p>To ensure the file landed where intended, I can run the following command. The ls command is the Linux equivalent of the Window’s dir command. </p>



<pre class="wp-block-code"><code>docker exec -it sql2019 ls /var/opt/mssql/backup</code></pre>



<figure class="wp-block-image size-large is-resized"><a href="https://theserogroup.com/wp-content/uploads/2021/10/dockerls.png"><img loading="lazy" decoding="async" src="https://theserogroup.com/wp-content/uploads/2021/10/dockerls-1024x319.png" alt="Docker ls command" class="wp-image-4017" width="768" height="239" srcset="https://theserogroup.com/wp-content/uploads/2021/10/dockerls-1024x319.png 1024w, https://theserogroup.com/wp-content/uploads/2021/10/dockerls-300x94.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/dockerls-768x240.png 768w, https://theserogroup.com/wp-content/uploads/2021/10/dockerls.png 1276w" sizes="auto, (max-width: 768px) 100vw, 768px" /></a></figure>



<h3 class="wp-block-heading">Restore the SQL Server backup</h3>



<p>Now we can restore the database backup as we typically would. Since I’m restoring a backup from another machine with different operating system, I need to move the data and log files when I restore the backup. </p>



<p>Run the following command in Azure Data Studio (or SQL Server Management Studio) to get a list of the database files for this database. </p>



<pre class="wp-block-code"><code>
RESTORE FILELISTONLY FROM DISK = '/var/opt/mssql/backup/BaseballData.bak';
</code></pre>



<figure class="wp-block-image size-full is-resized"><a href="https://theserogroup.com/wp-content/uploads/2021/10/SQLFilelist.png"><img loading="lazy" decoding="async" src="https://theserogroup.com/wp-content/uploads/2021/10/SQLFilelist.png" alt="Restore FilelistOnly" class="wp-image-4019" width="735" height="228" srcset="https://theserogroup.com/wp-content/uploads/2021/10/SQLFilelist.png 980w, https://theserogroup.com/wp-content/uploads/2021/10/SQLFilelist-300x93.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/SQLFilelist-768x238.png 768w" sizes="auto, (max-width: 735px) 100vw, 735px" /></a></figure>



<p>Now, I can restore the database using the following TSQL command. Notice I’m moving the physical files to a new location in the container. </p>



<pre class="wp-block-code"><code>RESTORE DATABASE BaseballData 
    FROM DISK='/var/opt/mssql/backup/BaseballData.bak' 
    WITH MOVE 'Baseball' TO '/var/opt/mssql/data/Baseball.mdf', 
    MOVE 'Baseball_log' TO '/var/opt/mssql/data/Baseball_log.ldf';</code></pre>



<p>You can see the new database in Azure Data Studio. You can use it just as you would any other SQL Server database.</p>



<figure class="wp-block-image size-large is-resized"><a href="https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored.png"><img loading="lazy" decoding="async" src="https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored-1024x294.png" alt="Restored database" class="wp-image-4021" width="1024" height="294" srcset="https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored-1024x294.png 1024w, https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored-300x86.png 300w, https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored-768x221.png 768w, https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored-1536x441.png 1536w, https://theserogroup.com/wp-content/uploads/2021/10/ADSSQLdatabaserestored.png 1838w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<h2 class="wp-block-heading">Stopping and starting a SQL Server Docker container </h2>



<p>If you&#8217;re using the SQL Server Docker container in a development or test environment, you may want to stop it when you&#8217;re not using it. Here&#8217;s how you can easily do that using a Windows command prompt. Replace sql2019 with the name of your instance. </p>



<pre class="wp-block-code"><code>docker stop sql2019</code></pre>



<p>To start the Docker container again, just run the following command. </p>



<pre class="wp-block-code"><code>docker start sql2019</code></pre>



<h2 class="wp-block-heading">Some more information</h2>



<p>Looking for some additional SQL Server information? The following posts may be helpful.</p>



<ul class="wp-block-list"><li><a href="https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&amp;pivots=cs1-cmd">Docker: Install containers for SQL Server on Linux &#8211; SQL Server | Microsoft Docs</a></li><li><a href="https://docs.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/database-server-container">Use a database server running as a container | Microsoft Docs</a></li><li><a href="https://theserogroup.com/sql-server/what-sql-server-version-am-i-running/">What SQL Server Version Am I Running?</a></li><li><a href="https://theserogroup.com/sql-server/do-i-really-need-sql-server-enterprise-edition/">Do I Really Need SQL Server Enterprise Edition?</a></li><li><a href="https://theserogroup.com/sql-server/script-how-long-until-my-sql-server-backup-restore-completes/">Script: How Long Until My SQL Server Backup/Restore Completes?</a></li><li><a href="https://theserogroup.com/training/want-to-learn-sql-server-here-are-3-free-sources/">Want to Learn SQL Server? Here Are 3 Free Sources</a></li></ul>



<h2 class="wp-block-heading">Want to work with The SERO Group?</h2>



<p>Want to learn more about how SERO Group helps organizations take the guesswork out of managing their SQL Servers? It’s easy and there is no obligation.&nbsp;</p>



<p><a href="https://calendly.com/joe_webb" target="_blank" rel="noreferrer noopener">Schedule a call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/">Getting Started with SQL Server in a Docker Container</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theserogroup.com/sql-server/getting-started-with-sql-server-in-a-docker-container/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3993</post-id>	</item>
	</channel>
</rss>
