What is docker and how we can use it?

Docker is defined as “an open-source project that automates the deployment of software applications inside containers by providing an additional layer of abstraction and automation of OS-level virtualization on Linux”. Simply said, Docker is a tool that allows developers to easily deploy their applications in a container(a kind of a sandbox) to run on their host operative system.

So what are containers?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. It contains everything needed to run an application: code, runtime, system tools, system libraries, and settings. This makes it easier to develop, package and deploy applications. In the case of new hires, the onboarding procedure is basically pulling a docker container image

We already have virtual machines, why should we use Docker?

  • VMs are an abstraction of physical hardware turning one server into many servers.
  • Each VM has it’s own operative system, libraries, and binaries.
  • For our app to run, we need to install all the dependencies we need.
  • Might use lots of space, and can be slow to boot.

On the other hand, containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine in their own isolated user space. They take less space than VM and are easier to manage.

Multi-container applications can be defined with docker-compose tool. Developer uses a YAML file to specify application services and how are they related.

version: '3'
   build: .
   - "5000:5000"
   - .:/code
   - logvolume01:/var/log
   - redis
   image: redis

Containers can also be orchestrated, which is all about managing the lifecycles of containers.

With orcestration developers can automate and control:

  • Provisioning and deployment of containers
  • Redundancy and availability of containers
  • Scaling up or removing containers to spread application load
  • Load balancing of service discovery between containers

This is really helpful in a microservice architecture, where applications are decoupled into discrete services, and packaged into separate containers.