“Write Once, Run Anywhere”
-Sun Microsystems about Java, 1995
“Build Once, Run Everywhere”
-Docker about any piece of software, 2013
Docker is a set of projects, tools, pieces of software that come together to form a platform or ecosystem around creating a unit called “Image” and running this Image as a “Container” on any
Image and Container
The Image is the most important thing in the docker world.
The Image is used to create Container. A Container can be thought of as an instance of an Image. The Docker Image is a static thing, not a process in memory. Its sole purpose is to run the process.
The only three things that can be done with a Docker Image are:
● Build an Image
● Launch a Container using Image
● Delete an Image
Instance of an image/running program with it's own isolated set of hardware resources are known as Containers.
As the Container is a running entity, we have more things to do with it. We can:
● Stop the Container
● Start the Container
● Run a command into the Container
● Watch the logs
In reference to Object-Oriented Programming, we may consider an Image as a Class and Container as an instance of the Class, i.e., an Object
Difference between Virtual Machines (VM) and Containers
A Virtual Machines is a running instance of an Operating System on top of another Operating System. It is heavy-weighted and uses many resources. On the other hand, Containers run as processes in the host Operating System. They are a light-weight way to deploy an application without having the full infrastructure of physical VM.
Is Docker always preferred? Is Virtualization dead?
The answer is No! Virtualization is not dead. It is just that for some use-cases, containerization is better than virtualization. There have been several cases where, in an organization, both containers and VMs are running on a particular micro service.
Using Docker, however, provides us with some additional benefits such as higher speed, easier portability, platform-independence, higher efficiency and lower computing cost.
As you may remember, Docker allows to build, ship and run any software. But before shipping, we need to build and run. There are mainly two base concepts: an Image and a Container.
The workflow can be:
- Build Images with Docker
- Use the built images to run Containers.
Images can be built with the help of Dockerfile. A Dockerfile is a plain text file which has some lines of configuration placed inside of it. This configuration defines the behavior of the container or what it does upon starting up. The next step is to build the Dockerfile. This can be done with the help of a command called
docker build. The final step is to run the built file with the help of
docker run command.
Every time we deploy an Image, we get a container.
The running instance of an Image is called container.
Apart from creating our own images, we can list out all images in the local copy of docker by using the command
Some other commands that can be used to work with images:
- docker run
- docker default
- docker publish
- docker ps
- docker stop
- docker image run
Can we share the Image?
We can share Images on Dockerhub. The Dockerhub is a registry/repository of free public Images that we can freely download and run on our local computer.
Working with Registries
Some handy and most-frequently used docker commands while working with registries:
- docker pull
- docker tag
- docker login
- docker push
Building apps from Docker can be seen as running different containers on a single application. It is just like making a recipe out of different ingredients.
Docker Compose comes handy in order to build applications with the help of docker.
The Docker Compose allows us to write a recipe (application) for all the ingredients (containers).
Instead of typing commands all day, we can describe requirements set up in a configuration file (which is usually a .yaml file). Once we have a configuration file, we can then run the application using docker compose by the command:
$ docker –compose up –d
Cassandra and Kubernetes