Setup Nginx and SQL Server with Docker
Table of Contents
- Introduction
- So I'm Trying to Use Docker on My Mac
- Boom! Docker!!
- Now, How Do I Host My Content with Nginx
- Install SQL Server on Mac with Docker
- Conclusion
- Reference
Introduction
Docker supports both Windows and Mac as development machines. I have used VirtualBox from Sun Microsystems, VMware which is also a leader in system virtualization, and Microsoft Virtual PC. There are many more different kinds of virtualization software, but these are a few I have used and I think they're the main ones. Now, when I used these, they were all the same — I had to download them, then install the OS I wanted to use, then install the list of middleware I wanted for that system. It seemed reasonable to me at that moment, but if there's something faster and more reliable, would you use it? That sounds like Docker.
So I'm Trying to Use Docker on My Mac
Then, what! You can use SQL Server on Mac!
But Before That, Here's What I Did First
- Install Docker - Get the Community Stable Channel Version for Mac.
Move Docker to the Applications folder and run it.
When Docker is done, you'll see "Docker is now up and running." Now you can use your favorite command line terminal to run commands.

// get current docker's information
docker info
// get docker's version
docker version
// get current images store
docker images
// show running container
docker ps -a
Those commands are the basic commands. You will learn the Docker version and information from them. So, when you try something a little more advanced like the following — creating an Nginx HTTP web server — Nginx is an open-source HTTP server built for performance. When you type the following command in the terminal:
docker run -d -p 80:80 --name my-server nginx
With the above command, Docker will get the Nginx image from Docker Hub if your local machine doesn't have this Nginx image. Also, when you type localhost, you will see the Nginx sample website running.
// stop my Nginx web server
docker stop my-server
// start my Nginx web server
docker start my-server
// remove my Nginx web server
docker rm my-server

Boom! Docker!!
That's a surprise to me. If you compare it to using VirtualBox, it's just so easy and simple. Also, you don't need to install Linux — it just works, because Nginx currently supports Ubuntu, FreeBSD, CentOS, Debian, and other Linux distributions. That's cool.
Now, How Do I Host My Content with Nginx
I know I can run Nginx on my Mac without having to install Linux, using my Mac's localhost on port 80. Now, I want to develop something using this Nginx dev web server. First, let's prepare the following HTML:
Docker Nginx
hello!
My first Nginx Web Server
The next step is to tell Docker where your source code is. Assume your HTML is at the following location: {My Folder which has html}
docker run -d -p 80:80 -v {MyFolder path which contains html}:/usr/share/nginx/html:ro -d nginx

Cool, I think I like this simple easy setup.
Install SQL Server on Mac with Docker
You can use this command to install SQL Server 2017 on your Mac:
docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=' -p 1401:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest
Also, you can install the following npm package sql-cli for querying:
npm install -g sql-cli
// or run as administrator
sudo npm install -g sql-cli
In addition, Docker has a UI tool to manage settings called Kitematic.

Conclusion
Docker brings a new approach to development — it is fast. It works very well if you want to build a web server like Nginx for development but don't want to spend lots of time creating a Linux environment or setting up an Nginx web server. It works great if you want to set up a MongoDB dev environment but don't want to visit the website to choose the version, set up the Mongo service, and configure a basic user. If you use Docker, it handles the setup for you and supports both the command line and a UI interface with Kitematic. In addition, you can use Docker on Mac, Windows, and Linux. I'm very impressed with Docker — it'll definitely improve developer productivity.
Although Docker is fast and powerful, like any other tool it's not perfect and can't support every single scenario. What we need to know is that Docker images support Linux, so if any middleware can be built for Linux, Docker can support it. That's why when Microsoft added SQL Server 2017 support on Linux, you could use the container on Docker — but you can't use SQL Server 2015 or lower versions. You also can't use IIS on Docker, because IIS on Linux is not supported at this time.