Docker here docker there docker everywhere - Getting started with docker in .NET with F#
If you are in IT world, you surely heard or read about docker. There was / is a huge hype about this technology. It looks like this one might actually survive the initial ‘It’s awesome phase’. I was looking for some info about docker. It was confusing to get to know what docker really is. Too much marketing buzz words everywhere. In this post I will sum up all my notes about how to start with docker in .NET and F#. It will be like learning journey that might end as a simple tutorial on where to start.
Docker ? My first encounter with docker was through simple
tutorial . It’s a online interactive shell emulation that lets you execute some of the commands and get the basics of docker. Sadly, after finishing it you are left out with more questions than answers. You can start by reading official site docs. The most important thing to note is that docker is a kind of a runtime that enables you to create images that you can run on top of it.This concept is just like Virtual Machines, there are however differences. Docker is not creating full complete OS instance, instead it is creating lightweight containers that do share the kernel but are still isolated and separated from each other more. This process is more efficient both in time and memory space. It is easier and faster to create smaller containers instead of full VM’s. There are however some cons, you won’t get full isolation but who really needs that ? Other problem is … Windows is currently not supporting those small containers, we can only run Unix beacuse docker is using ‘Linux Containers’. You can still run docker on Windows, but you can’t create windows images. Microsoft promised to provide this support in new Win version.
Running Docker on Windows
To start using docker on windows go to - https://docs.docker.com/installation/windows/. Boot2Docker is all you need to get started. This tool will install VirtualBox, configure small Unix VM that you will use docker from and there is also a nice utility tool that will connect you to your virtual machine. Boot2Docker is a little unstable, while testing I encountered one issue with never ending docker loading. It looks like there are some with issues - https://forums.docker.com/t/boot2docker-hangs-then-crashes/401 . I had to reinstall Boot2Docker multiple times to get it working.
F# + docker
I want to create my first simple image that I will be able to use and write some F# code, compile and run it.There are existing images with F# that you can just download and start using, but in order to learn I want to create my own image. In order to do this I will define a docker file with set of instructions that define how to construct an image.
Those instructions are stored in DockerFile without extensions or dots. Thankfully Boot2Docker does have vi on board so I can use it to create this file.
1. touch DockerFile will create me a file First instruction would be to get me a Unix distro that I will run everything on top off.
2. To build image
Yey it works, behind the scenes it gets the debian DockerFile and goes from instruction to instruction creating a debian runtime. I could possibly write my own ‘debian’ image, but that would involve me learning about how to build Unix distro. Instead of that I can just point to external image and build on top of it. That is one of the beautiful things about docker. You can mix / match different images and build more complex ones using the basic ones.
3. In order to compile F# app i will need mono and fsharp compiler
-y - “Always Yes” so if there is any prompt in ‘apt-get’ installer just say yes -q - Quiet - makes the log less verbose
4. Building image
I got some errors from apt-get missing packages and the logs says to add - ‘apt-get update’. This is supposed to update the ‘apt-get’ list of packages.
‘sudo docker build’ - and couple minutes later you should have a nice image with debian + mono + fsharp.
5. Switching to more specialized image
Sadly in my case I got lot of errors while downloading ‘mono-complete’. Instead of building mono on my own, I have decided to change the base image and use some Unix distro with mono on board. Running ‘docker search mono’. Gave me a list of all the potential images, I decided to use ‘mono’.
Notice that I installing vim, I need some basic text editor to create first F# hello world app.
6. What now ? -Starting container I have base image, there is no container yet. What is a container you may ask ? Container is a running instance of image. To start interacting with container, you need to start some app on it. Most basic one is interactive shell, that will also enable me to work on top of container
7. Testing out F# Lets see if fsharp is here fsharpi should start F# interactive.
Yey, it’s here. To exit just type quit#;;
8. Creating folder + hello world source file I need folder and hello.fsx file
9. Hello World App
10. Compiling app
11. Running Hello World App
Uff, done. That wasn’t that hard. Now, you might ask so what ? You just compiled Hello World app … I can do this on my local machine, yep but this
brief tutorial is just a starting point, I have started exploring docker, because, I want to play with akka.net and F#. In next posts I will post more things about how to use docker to create multiple akka actors and how to write some simple distributed app. That will be fun, cause it is a new world for me. Docker is more complicated than that. It is quite sophisticated and you can create complex images with many dependencies. edit: You can use vagrant with docker Docker Misconceptions Pawel Sawicz just send me a nice link with some anty-hype opinion about docker Another nice link with some docker problems + a solution
Interesting links: Getting Started with Docker: Simplifying Devops