INSTALLATION OF SQL SERVER DOCKER CONTAINER IMAGES
Docker:
Docker is an
open-source container platform provider written in GO programming language.
It’s available for Linux, Windows, and MacOS. In addition, it also works in
Azure and AWS environments. Containers allow developers to package up an
application with all the parts it needs, such as libraries and other
dependencies, and deliver it all out as one package. It’s something similar to
Virtual Machines but without the guest operating system. They’re isolated, but
they share Host OS. That makes them smaller and more lightweight.
Here we will
use Docker to pull and run the SQL Server 2017 container image. Then connect
with sqlcmd to create database and run queries. This image consists of SQL
Server running on Linux based on Ubuntu 16.04. It can be used with the Docker
Engine 1.8+ on Linux or on Docker for Mac/Windows.
Prerequisites:
- Docker Engine 1.8+ on any supported Linux distribution or Docker for Mac/Windows.
- Minimum of 2 GB of disk space
- Minimum of 2 GB of RAM
Steps of Installation:
Pull the SQL Server 2017 Linux container image from Docker Hub.
sudo docker pull microsoft/mssql-server-linux:2017-latest
apt install docker.io
sudo docker pull microsoft/mssql-server-linux:2017-latest
To run the container image with Docker
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' \
-p 1433:1433 --name sql1 \
-d microsoft/mssql-server-linux:2017-latest
To view your Docker container. If the STATUS column shows a status of Up, then SQL Server is running in the container
sudo docker ps -a
Change the SA password:
sudo docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd \
-S localhost -U SA -P '<YourStrong!Passw0rd>' \
-Q 'ALTER LOGIN SA WITH PASSWORD="<YourNewStrong!Passw0rd>"'
command to start an interactive bash shell inside your running container
sudo docker exec -it sql1 "bash"
Once inside the container, connect locally with sqlcmd. Sqlcmd is not in the path by default, so you have to specify the full path.
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourNewStrong!Passw0rd>'
To end your sqlcmd session, type QUIT .Your container continues to run after you exit the interactive bash shell.
Connect from outside the container
We can also connect to the SQL Server instance on Docker machine from any external Linux, Windows, or macOS tool that supports SQL connections.
sqlcmd -S 10.3.2.4,1433 -U SA -P '<YourNewStrong!Passw0rd>'
SQL Server container can be start,stop and remove with the command
sudo docker start sql1
sudo docker stop sql1
sudo docker rm sql1