This blog post is about running SQL Server in a docker container on CentOS Linux distribution.
This was both an experiment and also for me to re-learn CentOS – years ago I had done a fair bit with CentOS – back when I was a true Operations Consultant. Up until last weekend I had been using Ubuntu – as it is really easy to use.
All SQL Server container images on docker are built on the Ubuntu image so I wondered – can I run it on a CentOS Linux server running docker?
BTW – the obvious answer is ‘yes, of course because it is just a container”.
But I wanted to try it out and see what differences there were.
The first main difference for me so far – remembering to run sudo when I want to elevate my permissions. This is a good thing – I did many bad things in Ubuntu that I should have thought about first – that is why sudo is a good thing for people like me…!!
So if you are thinking of running docker on CentOS and
Install the latest version of Docker CE:
$ sudo yum install docker-ce
If prompted to accept the GPG key, verify that the fingerprint matches
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
and if so, accept it.
Initially start docker:
sudo systemctl start docker
To make it start every time the Linux server
sudo systemctl enable docker
Download latest SQL server image:
sudo docker pull microsoft/mssql-server-linux:latest
Run up our container and assign a non-default port – in this case I am swapping out port 1433 to port 56969:
sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>' -e 'MSSQL_PID=Developer' -p 56669:1433 --name SQLServer-Docker-DEV -d microsoft/mssql-server-linux:latest
Port mapping is specified via -p host port:container port.
Therefore in my example above -p 56669:1433 means that port 56669 on the host (CentOS VM) is mapped to port 1433 in the container. I am not a fan of using the default port 1433 – mainly as I like to stipulate different ports for different SQL Server instances (QA vs UAT vs PROD). This means that all connection strings I create from outside the container will need to include port 56669. How do I remember this number – that’s where configuration management comes in – another blog post I think…
I also want to change the password to something more secure (and less published on the internet) and this allows me to also show you how to access the SQL tools which are built into the image:
sudo docker exec -it SQLServer-Docker-DEV "bash"
Once inside the container, connect locally with sqlcmd. Note that 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 '<YourStrong!Passw0rd>'
Once we have connected with sqlcmd we can then use our native T-SQL to change the password:
Now we can go to the Azure portal and allow access to this port:
My preference is to tie it right down to the hosts that I know will access the SQL Server instance running in this container on this CentOS VM hosted in Azure.
Kinda reminds me of the dream layers of the movie ‘Inception’.
In the next blog post – let’s connect to this VM using SQL Server Management Studio on our PC.