What I personally use Docker for

sebastian gomez
4 min readMay 25, 2018

--

I've been writing about Docker lately and it has bought some attention. I got many claps on my latest post on how to use the Docker for Windows client from WLS, you can check it out here.

But today I wanted to share what I use Docker for and why I found it super useful. It's one of those things that are so useful to me right now that got me into writing this post thinking it can help others, I need to spread the word.

I'm not a Docker wiz, I have not used Docker or any orchestration solution for production environments, but I do have some scenarios where I found Docker to be extremely useful.

My typical scenario is where I need to try or test something whose runtime I don't have in my everyday dev machine. Like Ruby, or Python, I don't have those runtimes installed. I use Windows and we all know what happens when you install too much crap on your machine. But still, sometimes I want (need?) to try something written in one of those languages I can run on my machine, most of the time, when I pull something from GitHub.

But recently I've found another cool use, which is having the possibility to test many DBMSs in my dev machine, without the need to install anything (other that Docker for Windows of course).

My day to day DBMS is SQL Server, I have an "old" 2014 instance which is currently stopped, and a 2016 instance. Sometimes I want to test some of the newer features of SQL Server 2017, should I install that on my machine? Heck no! Docker to the rescue.

I have a bat file in my PATH called sqlserver.bat which starts a SQL Server 2017 instance with just one line:

docker run --rm -p 1533:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=dbPassword! -e MSSQL_PID=Developer -d --name sqlserver microsoft/mssql-server-linux:2017-GA

This command will start a local instance of SQL Server 2017 running on a Linux container on my Windows machine, how cool is that?'

Let me go thru the parameters real quick: rm tells the engine to remove the container when it is stopped, that’s what I use cause I use the instance for one test at a time (every time). The p makes the port of the SQL Server (1433) engine be seeing on my host on the 1533 (because I already have SQL Server on the host). There are two environment variables that need to be set ACCEPT_EULA to Y and MSSQL_SA_PASSWORD to whatever you want your admin user (SA) to be. Keep in mind there’s a policy for this password. The d parameter is because I want the container to run detached of my command line, and name is obviously the name of the container.

So, now what? Well, if you believe me you there’s a SQL Server running on a Linux container on your Windows machine. But you don’t have to just believe me, and you can try it yourself. Open SQL Server Management Studio and try to connect to localhost,1533 using the SQL Server Authentication provided above (SA and the password set in the MSSQL_SA_PASSWORD environment variable).

Entering my SQL Server

I can even create GeneXus Knowledge Bases in that SQL Server instance, all I have to do is set this same credentials in the Create Knowledge Base dialog, also pointing at my localhost with the provided port (separated by a coma).

Also, maybe I need to test PostgreSQL or MySQL. I do have two more bat files to fire up these DBMS:

docker run --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=dbPassword -d --name mysql mysql:5.7.19

This one is called mysql.bat (of course) and will fire up an instance of MySQL, and the following:

docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=dbPassword --name postgres postgres:10-alpine

is called, you guessed it, postgresql.bat and it will fire up a PostreSQL instance.

When I’m done, it would just stop the container, and because of the rm flag, that will remove the container.

docker stop sqlserver

It’s out of the scope of this post, but you might have the need to keep the created Databases in your containers. In that case, every DBMS image has a way to provide the volume you should mount so the created databases are persisted in your host file system.

bat files in action

That's it for now, for my next trick I'll need an X Window server and an Ubuntu base image. It's awesome!

--

--

sebastian gomez

Husband, father of 3, developer, techie, marathoner. Research & Development at @Genexus, creator of @IsIt7373MAX