Understand Docker

If you were following trends in social web about “devops” and “cloud“, you’ve surely heard about Docker. So what’s Docker and why we use it ? In this post, I’ll try to answer this.


If you are a developer and participated in a big project in which you touch many layers, or you are a sysadmin gay, you have probably heard or said:

But it works on my machine

Yeah, this very recurring. So what’s the promise of Docker ?

Build once, Run anywhere !

What ?

The best way to describe Docker, is to use the official description phrase:

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.

This is means that if you’re a developer, don’t worry about the system in which your application will be running on, and if you’re a sysadmin don’t worry about different troubleshooting in deployment, Docker will create a container with the right version of your application dependencies. Indeed, Docker will help you to build, share and manage your Linux containers.

For more information about Docker:

Why ?

  • Isolation: servers, services, applications, etc.
  • Deployment: improve quality of deployment process.
  • Scalability: scaling is an easy process and straight-forward.
  • Teams: improve collaboration between different teams with different backgrounds: developers, sysadmins, testers & QA
  • Productivity: Bring up a new instance in few minutes
  • Simplification: dependency management, configuration, etc.

How ?

Docker uses a client/server architecture. Below a diagram describing the Docker architecture:


the Docker client communicates with the daemon via sockets. Users interact with daemon via the Docker client. Inside Docker, we have 3 main terminologies:

  • Docker images: this is a read-only template for a service/application, an image can maintain a Debian OS with PostgreSQL, a Debian OS with Apache and your web application, etc.
  • Docker registries: which is also called Docker Hub, which contain a huge numbers of images: your images and others’ images. You can download a docker image with this command: docker pull <image-name>
  • Docker containers: this is the container of your image which is the run component of Docker. Docker containers can be run, started, stopped, etc.

I hope that you find this post useful. If you find any error or have a suggestion, feel free to comment on. Thanks for reading !


Installing different python versions in ubuntu

Since I write python code that should be running on different python versions, I have to install multiple python versions on my workstation. As usually, I believe that we should do everything well as we can :).

This post is a description of my procedure to get different python versions installed in my Ubuntu workstation.

Installing Multiple Versions

Ubuntu typically only supports one python 2.x version and one 3.x version at a time.  There’s a popular PPA called deadsnakes that contains older versions of python. To install it you should run the below commands:

$ sudo add-apt-repository ppa:fkrull/deadsnakes
$ sudo apt-get update

I’ve a Ubuntu 14.04 already installed in my workstation (So I’ve both python2.7 and python3.4). So, I’ll install versions 2.6 and 3.3.

$ sudo apt-get install python2.6 python3.3

Let’s check the default python version by running `python – V`

$ python -V
Python 2.7.6

Now, to manage the different python versions I will use an amazing Linux command: update-alternatives. According to Linux man page, ” update-alternatives maintain symbolic links determining default commands ”

Firstable, let’s install the different alternatives:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 10
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 20
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.3 30
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 40

To choose the default python version you should run the below command:

$ sudo update-alternatives --config python

Secondly, I can switch between the different Python versions easily with the previous command. However, Ubuntu runs multiple maintenance scripts and those script may break if I choose Python 2.6 as a default version.

Using virtualenv

I assume that we have different python version installed on your machine and you didn’t change the default python version (which is 2.7 in my case).

1. Installing virtualenv

$ sudo apt-get install python-virtualenv

2. Managing different python version
Suppose that I will start a new project which will run on Python 2.6. Using this solution, I will be able to manage different version of python and different version of any package I use. Great!

$ virtualenv -p /usr/bin/python2.6 ~/.envs/project_x_py2.6
Running virtualenv with interpreter /usr/bin/python2.6
New python executable in ~/.envs/project_x_py2.6/bin/python2.6
Also creating executable in ~/.envs/project_x_py2.6/bin/python
Installing distribute....................................done.
Installing pip.....................done.

3. Activating virtualenv
Before that you can install any package for this project, you should activate it:

$ source ~/.envs/project_x_py2.6/bin/activate

Now, If we check the default python version used for this project:

$ python -V
Python 2.6.9
$ which python

When you’re gone with the project, just deactivate its virtualenv and you can back to it when you need by activating it

$ deactivate