Sunday, October 21, 2018

Setup Microsoft SQL Developer environment in a few minutes using Docker

Let's say you have Windows 10 PC and would like to setup Microsoft SQL for the development and testing.

#Download the installer and install Docker for Windows
https://docs.docker.com/docker-for-windows/install/
(Caution: This is not for the production environment. It is only for the development and testing.)

#Switch Docker to Windows container after the install
#It is easy switch. Find the Docker tray icon in the task bar> right click > Switch to Windows Container

#To pull docker image from docker hub
#Use Windows PowerShell to run the Docker commands
docker pull microsoft/mssql-server-windows-developer

#For details: https://hub.docker.com/r/microsoft/mssql-server-windows-developer/

#To run the container using the pulled image
docker run -d -p 1433:1433 -e sa_password=Password1! -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer

#Above Docker command maps container port 1433 to host port 1433. Thus, host IP address or gateway.docker.internal can be used in SSMS to gain access to the database. Credentials: Local Authentication, sa username and Password1! for the password.

#Download and install SSMS from https://msdn.microsoft.com/en-us/library/mt238290.aspx

#More on Docker Networking features at https://docs.docker.com/docker-for-windows/networking/

#To check the currently running containers
docker ps

#To list the containers
docker container ls -all

#To view an IP of a docker container
docker inspect –format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ 

#To stop the container
docker container stop 

#To start the container
docker container start

#To remove the cotainer
docker rm

#To list the docker images
docker image ls

#To download and restore sample database from Microsoft
Visit https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15
Download one of the backup files you are interested in. Say, you downloaded Advendtureworks.bak file to c:\Downloads folder.
Copy the backup file to the MS SQL Server container. Top copy the file from the local host to the container, you have to STOP the container first.
docker container stop   
docker cp c:\Downloads\Adventureworks.bak   :c:\Users\Public\

Start the container. Now, follow the restore instruction provided in the earlier URL.


#For more docker commands, refer to
https://docs.docker.com/docker-for-windows/