Dockerizing Suave Music Store on mono

I've written the Suave Music Store GitBook, which helped quite a few people to get started with the Suave.IO library for creating web applications in F#. However the original version of tutorial didn't really feel x-platform, as it was designed to work on Windows only. I decided to revisit the tutorial and add 3 more sections describing how to convert the app to run on mono and place inside a Docker container.

Steps required

I've decided to split the desired goal into 3 parts:

  1. Converting form NuGet restore client to Paket
  2. Changing the database from SQL Server to Postgres
  3. Setting up docker containers

If you don't care much about details, and just want to check out the final code - follow this link.

Moving to paket

First step was to move away from the NuGet client, as it can bring some pain in conjunction with mono. Also Paket has a number of advantages comparing to the NuGet client - you can read about them here. Because of that, before trying to compile the application on my ubuntu box and mono, I made use of the paket convert-from-nuget command.

GitBook - Moving to paket section

Using postgres

Next step was to switch the database vendor from Microsoft SQL Server, which as the name might suggest can currently be run on Windows box only, to a more cross-platform Postgres. This required quite an effort, specially since I decided not to abandon the SQLProvider F# Type Provider I used to access SQL Server, which does support Postgres, but had subtle issues with uppercase tables / column names. Because of that I eventually made all names lowercase, and that resulted in necessity to adjust respective class properties generated by the type provider.

GitBook - Using postgres section

Bring docker into play

Finally after applying those changes I was able to configure docker images - database and application became separate images. To communicate between app and db containers, I made use of the docker container linking. One thing I'm not sure if I did right according to the docker philosophy was compiling the application before sending the compiled binaries to the docker build context. This way was easiest for me, as I needed to access a Postgres db schema upon compilation - that's what SQLProvider requires in order to compile correctly.

GitBook - Dockerizing on mono section

Summary

I get really excited when I think about that I managed to make it work, specially since I was a total noob with *nix stuff and Docker too (well ok, I probably still remain one). Go check out 3 new sections (10.2 - 10.4) of the Suave Music Tutorial here to read more details about the conversion. Till next time!