26
2017
What is Docker ? Getting Started with Docker
Docker is an open platform, which can be used for developing, shipping and running applications. Docker is designed to deliver an application fast by separating the application from the infrastructure.
Practically, it is a challenging task to create the exact same infrastructure in different environments in software development. Therefore, lots of issues occur during deployment and testing processes.
“It works on my machine, but it doesn’t work in production”, is a very common statement heard in the industry and it happens due to people using different infrastructure configurations in different environments, to deploy their artifact.
Therefore, industry professionals came up with various solutions and one of those is based on container base virtualization. A container creates an isolated environment using the kernel of the host operating system. Each container provides an isolated environment for each application. It uses container-based virtualization and the Docker engine creates and manages containers and provides a way to run the application in an isolated container.
It is an open platform, which can be used for developing, shipping and running applications. It is designed to deliver an application fast by separating the application from the infrastructure. it helps to ship, test and deploy code faster and shortens the cycle between writing and running code.
At its core, Docker provides a way to run almost any application securely isolated in a container. The isolation and security allows for running many containers simultaneously on the host server. Because of the lightweight nature of containers, it runs without the extra load of a hypervisor, so that Docker facilitates to get more out of the hardware.
Figure 1: Containers Architecture (Image source: www.docker.com)
When it comes to practical usage, It builds and run the environment on its own. Docker creates the same environment and infrastructure on a local machine, staging and production server.
In terms of interaction, Docker uses the client-server architecture. Docker-daemon is a Docker server which enables a container to be built, shipped and run. Docker client takes user input and sends it to the Docker-daemon where it builds, runs and distributes containers. Client and server can run on the same host or different hosts. In order to check client and server version “docker version” command can be executed.
Figure 3: Docker-Daemon and Docker Client (Image source: www.docker.com)
To understand Docker’s internals, you need to know about following workflow components. They are Dockerfile, Docker-image, container and Docker registry.
Dockerfile is a text file. It contains all the commands which are needed to create a Docker-image. Dockerfile offers many advantages for developers such as,
– Creating images using Dockerfiles is flexible because default options can be overridden
– Versioning has become easy with Dockerfile since you commit the Dockerfiles to version control to keep track of changes.
– Dockerfiles provide accountability when it comes to sharing images, so that others will be able to inspect the process of creating the image etc.
Docker-image is a read-only template which is used to create Docker-containers. Within the image, there are set of instructions for creating a container, like what programs to install, what folders and files to create etc. Developers can create their own images or use images that have been developed by others. Images are stored in the local registry or public registry. An image can be modified to create other images. The definition of an image is contained in a text file with a structured syntax referred to as a Dockerfile.
Docker-container is an isolated platform environment and it is a running instance of the image. Therefore, a Docker-container can be treated as a runtime object. Inside the Docker-container, it has everything that is required to run applications and containers can have one or more images. Using the command line interface or Docker API. Docker-containers can be started,stopped, moved or deleted.
Docker registry is the place which store Docker-images and it contains Docker repositories. and these repositories have Docker images. Docker hub is the public registry that contains many images for use. It has many official repositories and also has user specific repositories. These repositories have an introduction about repositories, instructions about how to use images and tags of various images in the repository.
Figure 4: Workflow of the Docker Components
Docker-images can be downloaded to the local machine by pulling them from the Docker registry. The customization for the Docker-image can be done by editing the Dockerfile, since Dockerfile contains all the commands that are needed to create a Docker-image. A new Docker-image can be created by commenting the Dockerfile and the new Docker-image can be stored in the local registry or pushed to a public registry.
Docker-image will create the container and run the application and Docker-images are read-only templates from which Docker-containers are launched and each image consists of a series of layers. Every Docker-image starts from a base image. An example is that the base image may be Ubuntu or Apache depending on the need. Docker-images are created based on a set of instruction and each instruction creates a new layer in the Docker-image. All these instructions are stored in a file called Dockerfile. When an image create request is executed, these instructions are executed and generates the final image.
These Docker-images can be stored in Docker registry. A Docker-images can be pushed to a public registry such as a Docker hub or own registry in the local environment. That image tells Docker what the container holds, what process to run when the container is launched, and a variety of other configuration data as needed.
Docker CLI facilitates to create, configure and run a Docker-image. Below are some basic Docker commands and their usages.
docker: This command will list down all the available Docker commands.
docker version: Show Docker client and server(daemon) information.
docker build: Build Docker image.
docker images: List down all the images in local registry.
docker ps: List down running Docker-containers.
docker run: Run Docker image.
Following image shows how to create a container using standard Tomcat.
References
- https://blog.xenproject.org/2015/08/11/will-docker-replace-virtual-machines/
- https://www.youtube.com/watch?v=mt5NDVK0Eg&index=6&list=PLaZW_dTdSDq6lfJJuvjz2wWHh8c3CSzvS
- https://www.docker.com/
- https://www.docker.com/what-docker
Authors
- Lahiru Nanayakkara
- Savani Samarathunga