SQL Server 2017 (on Linux) in Mac Docker – Part 2

Hello Friends!

In continuation to my previous blog, I’m going to showcase how Docker images works hand to hand with containers.

As you saw my docker is able to sense the SQL Server 2017 image, let’s go ahead and create a container from it which is running instance of the image.

Setting Up a “Container” From the Image

Before that I would like to bring few things about Dockers and worth knowing those facts. Totally deepending how familiar is someone with Docker. You may or may not be aware that containers are not stateful. Once you delete a container, everything is deleted. Means you’ve lost all your data/work/etc. However, Docker has a feature called “Volumes”, another way to retain “state” between docker instances. So when one instance is shut down the “state” is stored in a Volume. When another container instance is up respective volume provides the container with “state” from the previous instance. This way possible to use containers for databases.

Create volume container

Command to create container as follows:

My container’s name is sqldata

docker create -v /var/opt/mssql --name sqldata microsoft/mssql-server-linux /bin/true

Screen Shot 2017-11-05 at 7.37.56 AM

This volume container still uses the image as its base. But we won’t be running SQL Server from this instance.

Creating SQL Server container

As volume container is created next step it to create a container to run SQL Server. This container will use the data volume container for the persisted data.

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Passw0rd' -p 1433:1433 --volumes-from sqldata -d --name sql-server microsoft/mssql-server-linux

Screen Shot 2017-11-05 at 7.39.09 AM

In aforesaid command there are two environment variables

  • accept_eula
  • sa_password

Both are required.

  • userid is ‘sa’.
  • password requirements as Per SQL Server 2017 on Linux. (8 characters minimum)

Once aforesaid command is executed successfully let’s go ahead check containers. It only shows the regular containers.

docker ps

Screen Shot 2017-11-05 at 7.40.04 AM

The volume container is hidden so need to use –a switch.

docker image ps –a

Screen Shot 2017-11-05 at 7.40.39 AM

I noticed that the container I will be using to run SQL Server is on a port 1433 but data volume container’s status is “Created”. It doesn’t have a port or not exposed on a port.

Test the SQL Server 2017 on Mac Docker with SQL Command Line

The command lines tools for Mac are sql-cli. You’ve to have a NPM utility to install sql-cli interface.

You can install that with:

npm install -g sql-cli

Screen Shot 2017-11-05 at 7.51.45 AM

Start it up with the mssql command.

To minimum you need connect is to identify the server (which is at localhost by default, you don’t need to specify the port) and the password. It will presume sa for userid.

If it’s successful, you’ll get some information followed by a new prompt, mssql.

mssql -s localhost –u sa –p

Screen Shot 2017-11-05 at 7.53.09 AM

Wonderful! Everything is working as expected to far. My docker on MacBook is able to run SQL Server 2017 on Linux, seamlessly.

In my next blog, I’ll talk about the Microsoft SQL Server extension in Visual Studio code, running on MacBook. That would be real fun playing nicely with whole bunch of technologies. You may go ahead and download Visual Studio for MacBook from here.

Happy Learning!

Avanish Panchal
Regional Head – DataPlatformGeeks & DPS2017 Core Team Member
Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook

Follow Avanish Panchal on Twitter | Follow Avanish Panchal on FaceBook


About Avanish Panchal

Avanish carries around 15 years of experience in IT industry. He is post graduate in Computer Science, followed by Masters in Business Administration. He has worked on multiple technologies like SQL Server, .net & Sybase with world largest bank(s)/IT consulting firm(s) like JPMorganChase, CapGemini, Datamatics etc. Currently holds position of Database Architect in BioPharma Global Leader. His area of focus are SQL Server DB Engine, Security, Storage, Virtualization & Infrastructure Consolidation. Passionate for delivering Database IT Infrastructure to satisfy and exceed the needs of the enterprise. You may find him active on various forums like SQLBangalore, SQLServerGeeks & many more. His SQL Server passion helped him to be the Core Team member of Asia's First SQL Server Conference in 2015 @ Bangalore (#SSGAS2015).

View all posts by Avanish Panchal →

Leave a Reply

Your email address will not be published.