Setup Nginx and SQL Server with Docker

2017/5/35 min read
bookmark this

Another cool name, Docker..!?

Docker supports both Windows and Mac and builds as the dev machine. I have used The VirtualBox from Sun Micrososytems, VMWare which is also a leader in the system virtualization and Microsoft Virtual PC. There's much more different kind of virtualization software too but these are few just I have used and I think they're the main ones. Now, when I used these, they all the same, I have to download them then install the OS I want to use, then install the list of middleware I want for that system. Seems like reasonable to me at that moment, but if there's something faster more reliable for you, would you use? Sounds like that's 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 the step I do before go there.

1. Install Docker - Get the Community Stable Channel Version for Mac.

    Move Docker to Application 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.


// 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 command, you will know what's version and Docker information from the command. So, when you try something little advance like following, create NGINX http web server, NGINX is open source HTTP Server, build for performance. When you type the following command at the terminal.


docker run -d -p 80:80 --name my-server nginx

Above command, docker will get image Nginx from docker cloud library if your local doesn't have this Nginx image. Also, when you type localhost, you will see the Nginx sample web site running.


// stop my Nginx web server
docker stop my-server

// start my Nginx web server
docker start my-server

// remove my Ngix Web server
docker rm my-server

Boom! Docker!!

That's a surprise to me if you compare to use VirtualBox, it's just so easy and simple. Also, you don't need to install Linux and just works, because I think currently, Nginx is supporting on Ubuntu, FreeBSD, CentOS, Linux, debian or other Linux OS. That's cool.

Now, How do I Host my content with Nginx

I know I can run Nginx within my Mac and I don't have to install Linux and use my Mac's localhost's port 80. Now, I want to develop something by using this Nginx dev web server. First, let's prepare the following Html.


<html>
    <head>
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
      <title>Docker Ningix</title>
    </head>
    <body>
        <section class="container">
                <h1>hello!</h1>
                <p>My first Nginx Web Server</p>
        </section>
    </body>
  </html>

The next step is, you have to tell Docker where is your source code, 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 could use this code to install SQL server 2017 to your mac.


docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>' -p 1401:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest

Also, you could install following npm sql-cli for query.


npm install -g sql-cli // or run as administrator sudo npm install -g sql-cli

In addition, Docker has new UI tools to manage the setting, Kitematic.

 

Conclusion

Docker brings the new idea for development, it is fast. It works very well if you want to build web server like Nginx for development but you don't want to spend lots of time for creating Linux Environment or setup Nginx web server. It works awesome if you want to setup MongoDB dev environment, but you don't want to go there website to choose what version, how to setup mongo service and setup basic user. If you use Docker it'll just the setup for you and support both in the command line and UI interface with Kitematic. In addition, you can use Docker on Mac, Windows, and Linux. I'm very impressed with this new idea of development Docker brings, it'll definitely make developer performance better.

Although, Docker is fast and powerful, like another tool there's no perfect and hard to support every single scenario. So far we need to know is, Docker images supporting Linux, so if any middle could build for Linux Docker could support. That's when Microsoft support SQL Server 2017 on Linux, you could use the container on Docker but you can't use SQL Server 2015 or lower version. You can't use IIS on docker, because IIS on Linux is not supporting at this moment. 

Reference