What is Docker?
Docker is an open source software that is used to package your application as a standalone bundle and execute it independent of the production environment.
Just like you have an executable file(.exe, .dmg, .deb etc) which you can run on any system, docker creates an executable called Image that contains your application code along with the dependencies that you want to add(bundled as a single file) .
These dependencies may include runtime environment, a configuration folder, any other external files.
Suppose you are developing an application using java programming language.
Inside the application code, you use some java syntax such as Lambda expressions or switch expressions, both of which are introduced in and after java 8 respectively.
Now, the application is bundled and given to client who is using java 6 runtime environment.
What will happen? You know the answer.
Similarly, if an application is developed in Python 3.6 and above, it might be using below statement to initialize a variable
# underscore in numeric value d = 1_00_000
But it will break in production if it uses Python 3.5
Here comes Docker with a solution.
It lets you bundle your java application(packaged as jar or war) along with the java runtime environment compatible with your code and even a web server or other files.
This bundle is called an image in Docker terms and can be executed on a system that has Docker installed.
Thus, in a nutshell, Docker removes the discrepancies between the development and production environments.
An image is a read only bundle that contains your application code and everything else that you want. An image is built using a dockerfile which contains instructions on how to build the image, what entities are to be kept in it.
An image can be distributed so that it is executed as a Docker container.
A Docker container is an executing image. A container executes in its own environment which is isolated from the system it is running on.
When a container is run, Docker creates an environment for this container where it can create, read, write or execute files.
There may be multiple containers for the same image as well as for different images. Also, the image may be placed locally on the system or it may be downloaded from a location also known as a registry.
Below illustration will clarify the relation among Docker image, container and host system.
Consider the system on which Docker is installed as a box and a container as another box placed inside it.
A container is started using
docker run command. We will be looking at different docker commands later.
Docker Architecture / Ecosystem
There are multiple components of which Docker is made up of. You might get a chance to work on some or all of the components.
Components or parts of Docker are
1. Docker CLI
This is the command line over which you issue commands to build image, start/stop a container etc. This is also referred to as Docker Client.
2. Docker deamon
Docker service that is responsible for performing actual tasks of building images, running container, stopping it, interacting with networks etc.
Docker daemon listens over REST requests. When you issue a command such as docker run on Docker CLI(client), it sends a REST request to Docker daemon.
A Docker daemon is also called Docker engine.
3. Docker Registry
A common or central location where images are stored. You might create your image and push it to a registry so that when you start a container, it pulls the image from the configured registry instead of finding it on local system.
Registries make sharing or distributing images easier. One such registry is Docker Hub.
4. Docker Objects
Entities that are used in a Docker environment such images, containers and services are called Docker objects. We already looked what are images and containers, services are discussed next.
5. Docker Services
Services are used for scaling containers across multiple Docker engines. Scaling means that when load on a container increases, it is distributed to different Docker engines.
Below image will demonstrate the components of Docker
In the coming sections, we will learn
- how to install Docker on a system,
- create an image using our own application code with example,
- start/stop a container, and
- Common Docker commands.