<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>2018-11 on Funky Si's Test</title><link>https://blog-test.funkysi1701.com/2018/11/</link><description>Recent content in 2018-11 on Funky Si's Test</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>funkysi1701@gmail.com (Simon Foster)</managingEditor><webMaster>funkysi1701@gmail.com (Simon Foster)</webMaster><lastBuildDate>Mon, 05 Nov 2018 00:00:00 +0000</lastBuildDate><atom:link href="https://blog-test.funkysi1701.com/2018/11/index.xml" rel="self" type="application/rss+xml"/><item><title>Run SQL Server in a Linux container</title><link>https://blog-test.funkysi1701.com/posts/2018/running-sql-server-on-a-linux-container-using-docker-for-windows/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 05 Nov 2018 00:00:00 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2018/running-sql-server-on-a-linux-container-using-docker-for-windows/</guid><category term="Windows">Windows</category><category term="Docker">Docker</category><category term="SQL">SQL</category><category term="Linux">Linux</category><description>&lt;p&gt;Recently I have been investigating what all the fuss is about Docker and it has been well worth my time as Docker is pretty awesome for automating stuff.&lt;/p&gt;
&lt;p&gt;My development environment has typically required installing SQL Server. SQL is a bit of a beast with lots of options and takes time to setup how you want.&lt;/p&gt;
&lt;p&gt;However since Microsoft have now created a version of SQL Server that runs on Linux you can run SQL Server in a Linux container with only a few commands.&lt;/p&gt;
&lt;p&gt;I am going to assume you already have Docker for windows installed on your development machine. If not head over to &lt;a href="https://docs.docker.com/docker-for-windows/install/#where-to-go-next" target="_blank" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;
and find out how.&lt;/p&gt;
&lt;p&gt;The Microsoft guide to setting up SQL Server in a Linux container can be found &lt;a href="https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017" target="_blank" rel="noopener noreferrer"&gt;here&lt;/a&gt;
.&lt;/p&gt;
&lt;p&gt;First you need to download the image. In a powershell window run:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;docker pull mcr.microsoft.com/mssql/server:2017-latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This downloads the latest sql server image.&lt;/p&gt;
&lt;p&gt;To run this image run the following:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;docker run -e &amp;#34;ACCEPT_EULA=Y&amp;#34; -e &amp;#34;SA_PASSWORD=password&amp;#34;
-p 1433:1433 --name sql
-d mcr.microsoft.com/mssql/server:2017-latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To run a SQL Server image you are required to accept the terms and conditions and set a default sa password. These are added as environment variables with the -e flag.&lt;/p&gt;
&lt;p&gt;You also need to set the ports that your container will run on (1433 is the default SQL port) and give your container a name, in this case &amp;ldquo;sql&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;If you have already installed SQL Server you will not be able to run the container on the same port as your local install. To solve this you can select a different port.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;docker run -e &amp;#34;ACCEPT_EULA=Y&amp;#34; -e &amp;#34;SA_PASSWORD=password&amp;#34;
-p 1434:1433 --name sql
-d mcr.microsoft.com/mssql/server:2017-latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;-p 1434:1433 maps the 1433 port on the container to port 1434 of your local environment.&lt;/p&gt;
&lt;p&gt;Once you have run this command you can connect SQL Server Management Studio (SSMS) to (local) or (local),1434 if you are using a different port using the credentials you provided and execute any SQL you like.&lt;/p&gt;
&lt;p&gt;If your development environment requires windows authentication this of course is not for you, if it doesn’t you are good to go.&lt;/p&gt;
&lt;p&gt;The development environment I have been using has various powershell scripts for setting things up. These assume windows auth. However I have adapted them to take custom credentials.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$credential = Get-Credential $server.ConnectionContext.LoginSecure=$false
$server.ConnectionContext.set_Login($credential.UserName)
$server.ConnectionContext.set_SecurePassword($credential.Password)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Get-Credential command creates a dialog where you can enter SQL credentials, this is then stored in a variable and used in the rest of the script.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How do I restore a backup file to my container?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Run:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;docker exec -it sql mkdir /var/opt/mssql/backup
docker cp database.bak sql:/var/opt/mssql/backup
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This creates a backup folder and copies a backup file from your local environment to the container. You can then use management studio to restore the backup file (or you could write a sql script to do it). One thing to note when restoring databases, make sure the files are restored to Linux locations not windows locations.&lt;/p&gt;
&lt;p&gt;The only issues I have encountered so far are the lack of support for SSIS packages and no windows auth. There are sql server windows images available which I haven’t tried yet which may work better with some of these options.&lt;/p&gt;</description></item></channel></rss>