Docker for development environments
Autor: Glaudiston Gomes da Silva | Publicado: 2015-05-05T14:40:00-03:00

Docker is awesome. With it you can abstract almost anything. Once I read a tweet that says something like: "No matter the question, docker is is the answer". I think it's true, not because docker itself solve the question, but because it's a box, and the answers can be inside the box, so it's ease to carry on.

It's clear for me how it can be benefit to not only for productions environments. but for developments environments too.
I think some readers can not understand very well docker, so I'll try to be very instructive.

Conceptually, "docker" gives you a box, so you can organize your things inside the box, if you want a bigger box you can get it from docker too. But you need to know what you want to put in the box to choice the correct box from docker.

Docker use some advanced linux techniques to create a secure sandbox, separating your thinks from the real system. Inside docker, you can not see (per default) the real filesystem, memory and cpu, processes, network connections and interfaces. Seems like virtualization but it's different.

Why docker and virtualization are different ?
Well, in virtualization, you create a complete hardware structure, and load all operation system.
I see 2 big issues on it.
1. Load it is heavy and very, very slow.
2. Since a VM is a new layer of hardware translation, it can not be faster as run your code on host directly.

These 2 issues do not exist in docker, because it run all your things inside the loaded linux kernel.

Of course there are limitations too.
The main limitation in my opinion, is that you can not run windows code inside docker natively. but you can run docker inside the windows(using virtualization).

But back to main topic, how can a developer team be benefit from docker ?
Well, what matter in docker is the docker image. You need to create a docker image with all your dependencies and requisites to deploy your application, or just to share your environment with others team members.

How to do it?
Using docker is easy, you need to learn how to search base images:

docker search centos


Then choice your favorite, and just run it:

docker run -ti centos:centos bash

After it you has a container, a container is a running instance(sandboxed) of a image, into the container you can do anything you want (install and configure your environment), and after generate another image from your container.
To see yours containers, just do:

docker ps -a

To see your images, it's simple too:

docker images


BUT, this way is dirty and dangerous, because you can create a incremental images, too many times you install and remove things that leave unnecessary and possibly problematic trails of libraries and configurations.

To avoid it, you can use a DockerFile.

Dockerfile, is a script used by docker to build a image. So, you can configure anything (like you did in container) in dockerfile. then just build the image from dockerfile.

The problem is dockerfile can be slow to build, due downloading dependencies and other actions, so you can optimize it by creating a custom base image, or caching webfiles, but I do prefer a custom base image.

A custom base image is just a image builded from you with all dependencies. So, it can be base for the final image for your project.

To know how to create a dockerFile, read the documentation from docker project:
https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile

You can connect your docker container to your Xorg server, then you can load any graphical application, like eclipse, in your X server host, without install Xorg in docker container.
To do it, here a sample dockerFile to download, install and run eclipse on a centos:docker:

FROM centos:centos6
ENV DISPLAY :0
RUN yum install -y git wget tar gzip java-1.7.0-openjdk-devel.x86_64
RUN wget http://eclipse.c3sl.ufpr.br/technology/epp/downloads/release/luna/SR2/e
clipse-jee-luna-SR2-linux-gtk-x86_64.tar.gz
RUN tar xvf eclipse-jee-luna-SR2-linux-gtk-x86_64.tar.gz
CMD /eclipse/eclipse

you can build it with something like (in dockerfile dir):

docker build -t docker_eclipse .

just run it with:

docker run -v /tmp/.X11-unix:/tmp/.X11-unix docker_eclipse