Originally published @ hasnode.
Heredia, Costa Rica, 2022-11-13
So, have you ever wanted to try some piece of software but the installation process just kills your buzz? This has happened to me countless times, but nowadays there are a number of solutions for this, depending on the type of software you want to use/test.
For say, over a decade now, it is possible to have a PC within a PC. Computer as a service, is an appropriate term. For example, you could download ready-made virtual PC's from OS Boxes for a lot of Linux operating systems. Granted, though, there aren't many that boast specific applications. For example, I'd love to be able to download a "developer PC" that comes with things like MySQL Workbench, SQL Server Management Studio and other software of the likes of those. Still, it is possible to prepare one such image and distribute it.
Windows has had 2 operating system subsystems for a very long time (which may come as a shock to some): A Windows 32-bit subsystem and a Linux subsystem. For a long time.
However, these have always been there silently doing stuff. For example, the Win32 subsystem automatically launches any time you run a 32-bit application in a 64-bit Windows installation (which is pretty much every PC now).
The Linux subsystem was barely ever used (in my limited experience, that is), but now Microsoft released a "version 2" that works far better and is simpler to use. With WSL v2 it is as simple as going to the Windows Store and installing a Linux OS, like Debian. Then debian away, in Windows!
Dockerizing is what's hot today, and while on the surface it looks super similar to virtual machines, Docker containers are vastly different.
For starters, you do not get the immersive inside another PC feeling the virtual machine provides. You are not moving a mouse in another PC and you are not seeing the display of another PC.
Instead, Docker containers are meant to run services and similar software applications. Examples would be database servers, web servers, and pretty much any service that offers services through a network connection.
Long story, short:
- Install Docker Desktop, if you haven't done so. It is available @ this link.
- Go to this URL to obtain instructions on how to run MySQL inside Docker.
Step 2 above is pretty much the final stuff, but since this is probably confusing to newcomers, I'll detail. Especially worth noting here is that the example there can be simplified for the purposes of playing around with MySQL.
The important thing in the URL I presented is this command line:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This is command in the URL, verbatim, but requires some value replacements, so use the following, which also has a (missing?) switch to export the MySQL port:
docker run -p 3306:3306 --name mysql-local -e MYSQL_ROOT_PASSWORD=catOnKeyb0ard -d mysql:8.0.31
That will run MySQL with a root account with the password catOnKeyb0ard and will expose the container port number 3306 to the outside world (outside Docker) as, port number 3306. You see, the value after
<port to use outside>:<port to expose>. So it is a port mapping instruction. In plain English:
Docker, map port number
Yfrom my real PC (the host machine) to the container's port number
X, where I wrote
So that means whatever you put as
Y must not be in use in your real PC (host machine) by another program. For example, if you are playing, or want to play, Age Of Empires II Definitive Edition, you better not do
Y = 3000 because battleserver.exe will want that port free on your PC!
Anyway, back on topic.
The command, when executed in bash, command prompt or PowerShell, will tell Docker to go download the MySQL image for MySQLS v8.0.31 (latest version at the time of this writing), then use that image to create a container and run said container with the command line arguments we provided.
IMPORTANT: Once the container starts to run, you might see a prompt to allow Docker to pass your PC's firewall. On Windows, I am given the choice of private and public networks. Unless you know what you are doing, allow on private networks only.
And voilá! You now have MySQL running in your PC without really ever installing it.
So having it running will be particularly underwhelming if you cannot actually use it. So you need a consumer program. Something that can connect to MySQL and make use of it.
In my case, I simply installed MySQL Workbench in my (real) PC, connected to it and made a database, a couple of tables and inserted a few records.
These are my connection settings:
All that is missing in that screenshot is the password for the root user account, which is whatever you typed as password in the
docker run command above.
So this is it for this quick tutorial on how to test server-side software like databases. You could do the same for other database engines and some web servers.
Of particular interest to me and anyone learning or using structured logging, you can have have Seq running in no time in a Docker container. Seq was created by the same author of Serilog, which is what I consider to be the best logging library for structured logging in .Net.