"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Saturday, 7 July 2018

The joy of virtualization: Docker


I took a relative pause from experimenting with Raspberry Pi to report my first experiences with something completely different. One of the first things you realize while programming server-side is how your program is only one piece of a bigger puzzle. Your application usually runs inside a container, connects to a database, expose or consume services and so on ... Solving this puzzle means defining an installation procedure that becomes different and sometime more complex by changing or scaling the installation target.

Docker

Docker is an container platform that overcomes the installation problems by producing a ready-to-install standardized operating-system-level virtual machine, packed with everything your application needs to be run. Unlike other virtualization solutions a Docker image only contains what your application needs without having to install and run a full hardware simulation like, for example, in Virtual Box.

Installation

Docker is available in two versions a professional “enterprise” edition and a community one (Docker CE) free to download. Installing Docker CE on Ubuntu is just matter of adding Docker repository address
sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Then installing it using the usual apt command
sudo apt-get updatesudo apt-get install docker-ce
Once the installation completed the current user, or any user who will use Docker, must be added to the “docker” group.
sudo adduser maxx docker
After logging out and in again Docker was ready for use and command
docker info
Correctly reported the empty environment initial state

First run

In order to test Docker is correctly installed and running a simple “hello-world” image is available. Just by calling the command:
docker run hello-world
Docker take care of downloading the image from its repository, installing and running it.

Another interesting image to start with is, as suggested in hello-world printout, the “ubuntu” image that installs and starts a console-only Ubuntu virtual machine with no effort.


Eclipse IDE integration

Since one of the main use of a tool like Docker is in software development integration plug-ins are available for Eclipse as for most important IDE software.
The Eclipse Docker Tools plug-in can be easily installed from Eclipse Marketplace
after installation is completed the plug-in provides a new perspective displaying currently installed Docker images and containers. From here both can be started or controlled in many ways without the need of command line Docker commands.

Next steps ...

That’s all for now, in the near future I’ll try, of course, to develop a custom image but also experimenting with Docker and the Raspberry PI could be an interesting development.