Docker + Git = (Productivity)²

Shifting from Visual Source Safe to SVN seemed like going back to the past. Learning git seemed like it was really a step into dark ages. This changed overtime by using git for the past more than seven years. I have learned the hard way a lot of efficiency / productivity hacks. I still believe I am a long way from being totally efficient.

I have been using Python / Django for the past many years and being in that community the next big thing is virtual environment (venv). This gives the programmer the ability to keep a wonderful shell around every project and have an exclusive area. For a long time it felt life cannot be better than this until I stumbled upon docker (albiet a couple of years too late). In the interim I explored the idea of having VMs and the grand world of vagrant. These were too cumbersome to handle and were impeded by the lack of computing resources or internet bandwidth.

Docker outshines the any of the alternatives (that I have explored would love to hear of any better alternative) by the ability of being configured by only one command line. Yes only one command line can summon a working ngnix machine at your disposal.

$ docker run -dP dockersamples/static-site

The above command creates the docker container and exposes a port as well.

Use the first command to see the container id and then the subsequent command to view the port exposed.

$ docker ps
$ docker port {Container_id}

This is a very simple way of using docker container. So smoothly we have a container up and running. The beauty is that using it for your own project is not very complicated. There is a way to specify the container information like below in a docker-compose.yml file.

web:
    image: nginx
    volumes:
        - .:/usr/share/nginx/html/.
ports:
    - "8000:80"
environment:
    - NGINX_HOST=foobar.com
    - NGINX_PORT=80
command: /bin/bash -c "nginx -g 'daemon off;'"

This yml file is supported by a Dockerfile, which can contain useful information like the following.

FROM nginx
COPY index.html /usr/share/ngnix/html/index.html
CMD [ "nginx", "-g", "daemon off;" ]

The following command allows it to be run.

$ docker-compose up -d

So enough of commands and lets go back to the general idea of how it helps in productivity.

Dockerizing Project

So given the above scenario its helpful for the programmer(s) working on the project to have a consistent environment to push and test the code. This allows collaboration amongst a large team. Alongside using git for version control, dockerizing project can go a long way in avoiding pit falls of inconsistent, environments and most importantly avoiding the single largest bug of all “it was working on my machine/ locally”. This is ensured because everyone is building and testing code in “virtually the same machine” (i.e., machines or container build by the same script).

Multiple Stages of Development

The power of this approach becomes apparent when the setup is enhanced to add more machines to support the Software Development Workflow. The following containers can easily be added.

  • Development : The machine where all the latest code is deployed
  • Staging : A stable version of code which can be tested by testers and stake holders.
  • Production : The most stable and live code being used by users.

All of the above machines can be spun off by simply running a command.

A big bonus is that continuous integration tools can be integrated to ensure seamless testing and deployment.

Next stop : Kubernetes