Tuesday, May 30, 2017

Get a development instance of SQL Server up and running quickly using Docker

A few short years ago, I never would have thought that I could easily spin up a new SQL Server instance on a Mac. And yet, here we are. With Docker installed, I am half way to creating a new SQL Server database.

Full details are here, to give create where it is due, but the abridged instructions are as follows: Ensure that Docker is running, and then pull the official Docker container.

docker pull microsoft/mssql-server-linux:latest

The Docker container should be downloaded and configured within a few minutes. Your connection speed will have some effect on the process. But once it is ready you should be able to start it up. I chose to do two things to simply the next steps. 1) I created a variable named PASSWD, containing the password that I wished to use as the password for the SA account and 2) since Docker will return the container handle from the docker run command, I stored that container handle in a variable, thusly:

cid=`docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=${PASSWD}" -p 1433:1433 -d microsoft/mssql-server-linux`

I am able to connect to this image and fire up the SQL command shell to test out some basic commands against SQL Server.  

docker exec -it $cid /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $PASSWD

I get the sqlcmd prompt.

1> 

Let’s have a look at which tables are available.

1> EXEC sp_databases
2> go
DATABASE_NAME                                                                                                                    DATABASE_SIZE REMARKS                                                                                                                                                                                                                                                       
-------------------------------------------------------------------------------------------------------------------------------- ------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
master                                                                                                                                    5888 NULL                                                                                                                                                                                                                                                          
model                                                                                                                                    16384 NULL                                                                                                                                                                                                                                                          
msdb                                                                                                                                     14080 NULL                                                                                                                                                                                                                                                          
tempdb                                                                                                                                   16384 NULL   

Now that you have completed the preliminaries, we can exit out and shut down the image. Docker will storage all changes to the structure and content of databases, persisting it across sessions. So we will be able to pick back up later.

1> quit
docker stop $cid

You can confirm that the image has been stopped by checking the status using the docker ps command.

docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS                            PORTS               NAMES
29a0373654db        microsoft/mssql-server-linux   "/bin/sh -c /opt/m..."   6 minutes ago       Exited (137) About a minute ago


Note the “Exited” message. You now know how to get a development instance of SQL Server up and running quickly. Stay tuned for future posts.

1 comment:

  1. casino web - Deccasino
    Register and make fun88 soikeotot your first deposit and enjoy 메리트카지노 your favorite casino games, slots and table games. Register at Deccasino 카지노사이트 Casino, one of the largest online casinos

    ReplyDelete