Hi and welcome!

How to setup development environment for Docker 17-02-2015


This post is a part of series about Docker.

In the previous post we got the answer on question - why we need Docker.

Now let’s make our hands dirty!

Info For code samples, please, check GitHub repository - https://github.com/ssinica/blog-docker

Right now Docker works only on Linux. Yes, there are news about Docker on Windows, but this does not mean, that you will be able to run Ubuntu image on Windows server. So - we do not care :)

I will try guess - you are using Win or MacOS for development. Right? So to run Docker you will need a virtual machine with Linux. You can use Boot2Docker utility to try Docker, but I prefer to use Vagrant and VirtualBox right away. Because in real life you will need to build Docker images, write scripts, test different configurations, etc., so anyway at some point you will need Vagrant.

I like to have one GIT repository for everything my project needs - source code, deploy scripts, documentation, etc.. So all stuff related to build, deploy and configuration management I usually put into directory /infrastructure. I saw some people suggest to use something like /src/main/docker, but this does not have any relation to Maven, so…

In infrastructure directory there is Vagrantfile, with our virtual machine (Ubuntu 14.04) definition. As you can see I use Docker provisioner, which will install latest Docker on first run and pull Ubuntu 14.04 image from public registry.

Please, make sure you have kernel version supported by Docker, because if you try to run Docker on Ubuntu 12.02 with kernel 3.2, then everything will work, but with some strange side effects.

Also in infrastructure directory I have docker and scripts sub-directories, which will be mapped to /data folder in Vagrant. docker directory contains Dockerfiles used to build Docker images, and scripts directory contains,…, well, scripts :) (captain obvious mode is on)

In real project you will want to use some configuration management system to provision your servers, define configuration and control Docker containers. Like - Puppet, Chef or Ansible. But at this time we will try to keep it simple and will use old good bash scripts.

Now, let’s bootstrap our dev server.

cd infrastructure
vagrant up

Connect to srv-docker (if you did not noticed - I set host name for VM to srv-docker and IP to in Vagrantfile):

# password = vagrant
ssh -p 22 vagrant@

At the moment of writing this I use Docker 1.4.1:

root@srv-docker:~# docker -v
Docker version 1.4.1, build 5bc2ff8

And OS:

root@srv-docker:~# uname -a
Linux srv-docker 3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Now, when Docker is up and running, we are ready to build our first Docker image.

Next: How to build Docker images?