Understanding Docker as a developer: Part1

I am always excited to see new tools in the developers world and always wonder what good they can bring in the programmers life. Lately I used Docker and felt that this is what I always need. Like most developers I write code on my laptop or development machine. And ofcourse It runs on window or mac and mostly the production or qualification environment is linux based and very different from our development machine. And then mess happens when we deploy our application in production. Below I have tried to sum up my understanding and the basic questions that comes to everyones mind before using docker.

Why use Docker?

Due to different operating systems ,system packages, application supporting packages in the various environments of software development lifecycle, sometimes our application doesn’t run as expected. We need something that ensures that our application, related packges are same in every environment.

What is Docker?

Docker as the name suggests, are kind of containers that wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

Installing Docker is super-easy and one can follow the steps at docker site for the installation and quick startup guide. I am using windows and you will see these application installed after the installer exits.

docker1.png

You can open Docker Quickstart Terminal and can play with it by running basic commands(shown below).

docker –version shows the version related information

docker –help shows the varios docker related commands

docker images shows the various images in your docker machine

docker ps shows the various containers in your docker machine

Lets dive deeper.

What is an image?

Docker is based on concept of images which could be base OS or some other minimal image. Over this base image we can create more images by adding softwares, system packages, third party applications as required in development cycle. So the various changes made to the base image are saved in layes forming different images. The base image we can create ourselves by using dockerfile or downloading some image from docker hub.

Below is the screenshot from my machine and you can see base image is ubuntu and with additional changes I create new images that is similar to version control where we have differnt versions of source code but in docker we are maining incremental images upon commiting.

docker2.png

What is a container?

Now whats the purpose of images if we dont run it and use it. Whenever we start an image of our interest, docker create containers which are kind of instance of that image. we can run multiple conatiners of an image. In the screenshot below I started an image in my docker with bash shell or I can run it in background. I can see the list of running containers with the command docker ps

docker3.png

Accessing our container from host network or some other containers?

There are basically 3 approaches for this

  1. Exposing ports
  2. Port Binding
  3. Linking Containers

More about this in my next post. Let me know for any questions/corrections.

Written on November 3, 2016