Docker 101 – Getting started with Docker

What is Docker

As per Docker’s website
Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.”
Docker is basically, based on operating-system-level virtualization
Operating-system-level virtualization is a server-virtualization method where the kernel of an operating system allows for multiple isolated user-space instances, instead of just one. Such instances (sometimes called containerssoftware containers, virtualization engines (VE), virtual private servers (VPS), or jails) may look and feel like a real server from the point of view of its owners and users.”


Neccessary Vocabulary

Few terminologies, to get started with Docker.

Docker Hub

The public repo of Docker images i.e. from where ‘docker pull‘ gets the image, and ‘docker push‘ publishes.   It hosts public Docker images and provides services to help you build and manage your Docker environment.

DockerFile 

Is the conf file for building Docker images. A minimal DockerFile requires the mention of the base image to use i.e. any of the existing image, available locally or on the Docker hub.

Images

in simplest words, a Docker image is basically the OS file required to run the Docker container.

Layers

Each Docker image is stored as a series of read-only layers, maintaining the filesystem differences. These layers are stacked on top of each other to form a base for a container’s root filesystem. For example –  the Ubuntu 15.04 image with it’s 4 layers.
 docker layers

Storage Driver

The Docker storage driver is component responsible for managing the image layers and providing a single unified view of them i.e. a single image. An example is AuFS, or devicemapper, etc.
Docker images stored in layered form is possible because of storage drivers, which is the crux of Docker being very fast and highly storage efficient. In case of fully virtualized VM, a 1GB container image you would require 1GB x number of VMs storage space. But with Docker and AuFS working together, a single image will shared among all the containers i.e. for 1000 containers using a single base image, you might only require a little over 1GB of space for the containers OS.

Copy-on-write

Docker containers are resource efficient because, All the containers share a single copy of common parts of the OS, which get copied into a container’s write layer (mounted on container initialization) once write or change is made.

Container

is simply a live Docker image instance i.e. docker run <image_to_run>.
When you run a docker image i.e. instantiate a new container, a new thin, write-able layer gets added on top of the read-only layers, called as the “container layer”. All the changes made to the running container i.e. modifying files, creating new files, or deleting files, etc are written to this container layer. When the container is deleted, the write-able layer also gets deleted, hence you’ll end up with the starting image. i.e. relaunching the image will give you a fresh container, without any of the changes you made in the previous container. To keep the changes made to container, you need to commit them (docker volumes, explained next), doing so will give you  a new container. This is how the layers made Docker very fast i.e. each container (running instances) has it’s own container layer (write-able layer), this way multiple container on single Docker host can share the same underlying image (layers), and yet have their own private state. For example, downloading a single Ubuntu OS image (docker pull), you can run multiple containers, all using the same image, just with their own container layer.

Data volumes

Data volumes are the Docker host’s directories directly mounted on the containers. Data volumes are independent of the storage drivers. Contrary to the write-able layer the data in the data volumes persist on the Docker host, even when the container is deleted. Any number of data volumes can be mounted in a container, and multiple containers can also share one or more data volumes.


Install Docker

Here’s a step-by-step guide for installing Docker on CentOS 7.x – “Install Docker on CentOS 7.x


Docker commands

A brief overview of docker commands.
docker info

All the info about the docker engine i.e. storage driver, version.

Docker info

docker images

Gives the listing of locally available docker images i.e. pull-ed from docker hub, or newly build.

docker images

docker search

For searching images on docker hub i.e. public docker images library.

docker search

docker build

To create a docker image from a DockerFile.

docker push

To publish a docker image.

docker pull

For retreiving/downloading a docker image.

docker pull

docker run

For starting/initializing a docker image i.e. running a container.

docker run

docker ps

Lists all the docker processes i.e. the running containers.

docker ps

Leave a Reply

Your email address will not be published. Required fields are marked *