Building a Test Environment to Collaborate on dbatools3 min read

Problem

It has been a little over a year since I ran across the community that is dbatools.  Not in my career have I seen an online community of professionals been this welcoming and helpful to people on a daily basis.  dbatools is a collection of PowerShell functions that makes the life of a Microsoft SQL Database Administrator easier and helps automate those wish list items.  On top of that; the larger your environment the more help the tool gives you.

In the past I had always hacked together PowerShell scripts to accomplish a specific task.  Last year I committed to learning PowerShell from the ground up and get the fundamentals under my belt.  This was a success in my opinion.  There was a lot more to learn than just PowerShell, but I already covered that in my blog post.

When I first started it was tough to get all the pieces to work.  I had local installs of SQL 2008, 2008 R2, 2012, 2014, 2016, 2017 on my work laptop.  This is old school and is a method I used to keep different versions for testing things for my DBA job.  So in an effort to try and be a little more current with my technology I built a VirtualBox environment with a Windows Domain Controller and virtual machines for each version of SQL.  This was hard to maintain and spin up quickly.  The one thing I was able to do was to test Windows Clusters and test Availability Group scenarios easily.  My work environment heavily uses AG’s, so being able to run tests and scenarios was a good to have.

Note:  I tried Azure VM for testing, but thanks to corporate web restrictions this was not allowed.

Solution

Recently, I was introduced to the leading/bleeding edge of technology: Docker Containers.  After that I was privileged to help test the dbatools team PASS Summit Pre-Con lab setup.  They used an automated lab build process they developed to allow class participants the ability to host their own local lab using Docker Containers.  There purpose was to demonstrate the power of dbatools to the class with hands on demos.  My purpose is more to spin up a SQL development server to run new PowerShell code I am writing without harming a local install or virtual install.

 

The first thing I did was to complete the Container Series that Andrew Pruski (b | t) published.  This is a four part series on getting started with containers.  However, he has much more useful information on his blog and continues to add.

Below are the steps I took to build my dbatools Container testing environment.  This is all assuming you have already built your docker container infrastructure via Andrew’s posts or other method.

  1. Verify the container is running
  2. Now to find out what the IP is for our container by running the command:

  3. So our container is running as IP 172.19.134.55.
  4. Now for person preference I like to set a SQL Network Alias so I am not having to keep up with an IP address.
  5. So what this has done is allowed me to be able to connect to SQL Server running in my docker container by the IP or the Alias.
  6. Now lets run a command to show how easy we can connect dbatools to our SQL Server Instance dbatoolstesting
  7. As you can see I created a new login on the SQL Server using the New-DbaLogin function

Conclusion

While this is a very entry level instruction on getting started with Docker Containers with SQL and dbatools.  It can expand to much more.  Docker has the ability to have a “dockerfile” created.  That would allow you to share files, folders, restore databases, create custom images, and on and on.  You could build your own scenario to meet your need.  This is just the technology piece to get you started down your road.

Leave a Reply

Your email address will not be published. Required fields are marked *