/docker

The code that's used to create the dbatools SQL Server images on Docker Hub.

Primary LanguageTSQLMIT LicenseMIT

docker

This repo holds the Docker compose code that was used to create the images featured on dbatools.io/docker.

It's intended not only to help test out dbatools, but to also explore the creation of SQL Server-based containers for your own environment. The compose code is heavily commented and the repo is a work in progress as I'm also learning. Suggestions for improvement are welcome!

To read about the things I learned while creating these containers, along with tips and tricks, visit the wiki.

Get started

To get started and see the containers built in real-time, first clone this repo, then build the base images and containers using docker-compose. You can also use docker compose without the dash if you use Docker Desktop, as explained on 'Difference between "docker compose" and "docker-compose".'

git clone https://www.github.com/potatoqualitee/docker
cd docker\sqlinstance
docker-compose up -d

This will pull the SQL Server images from Microsoft's repo, then add a bunch of test objects (databases, logins, jobs, etc) using bash and sql files in this repo, and then make them available for you to connect to on the default port 1433 for the first instance and port 14333 for the second instance.

Note: If you're using ARM architecture (Apple M1 or Raspberry Pi), none of the High Availability commands will work, as ARM is only supported by SQL Edge, which is limited.

Time to play 🎉

Now we are setup to test commands against your two containers! You can login via SQL Server Management Studio or Azure Data Studio if you’d like to take a look first. The server name is localhost for the first instance and localhost,14333 for the second instance), the username is sqladmin and the password is dbatools.IO

image

Note that dbatools supports both using commas and colons to designate a port. When you use a comma, however, you must also use quotes: 'localhost,14333'. When using dbatools, we recommend just using localhost:14333.

$cred = Get-Credential sqladmin
Connect-DbaInstance -SqlInstance localhost, localhost:14333 -SqlCredential $cred

If you'd like to test more commands, check out dbatools and docker (updated!)

To stop the containers, run the following command in the docker\sqlinstance directory:

docker compose down

And if you'd like to remove the persisent volume it created for the containers to share data, use --volumes

docker compose down --volumes

Remove everything

If you want to uninstall, or start from a "clean" installation, docker compose can remove all the containers and volumes in one command.

docker builder prune -a -f
docker compose down --remove-orphans --volumes
docker rmi $(docker images -q "dbatools\/*")

Resources

Some of the best resources I found included:

Repos