DEV Community

Cover image for Beginner's guide to Docker
Anamika
Anamika

Posted on

Beginner's guide to Docker

“Write Once, Run Anywhere”
-Sun Microsystems about Java, 1995
“Build Once, Run Everywhere”
-Docker about any piece of software, 2013

What is Docker?

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
docker-ready system.

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
● etc.

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.

How does Docker work?

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:

  1. Build Images with Docker
  2. Use the built images to run Containers.

Build Image
Whenever we want to start up a new container, we must build the Image first. This is the similar to Object Oriented Programming, where we need to create a class in order to create an object.

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 docker images.
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

Can I build apps with Docker?

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

How can I learn Docker
Here are a few links and resources you may want to follow in case you want to learn docker :)
Dockerhub
Learn Docker

Addition-
Cassandra and Kubernetes

Top comments (11)

Collapse
 
noviicee profile image
Anamika

Coming soon -> Where does the data go?

Collapse
 
noviicee profile image
Anamika
Collapse
 
andres085 profile image
Andrés Fernando Martinez

Nice post

Collapse
 
noviicee profile image
Anamika

Thank you! :D

Collapse
 
lucidmach profile image
Nukala Suraj

Novice Friendly

Collapse
 
noviicee profile image
Anamika • Edited

Yup. Especially for newbies :D

Collapse
 
noviicee profile image
Anamika

Feel free to contact me in case of any query. I'll be happy to answer them ^_^

Collapse
 
adlersudo profile image
adler-sudo

Thank you!!!

Collapse
 
noviicee profile image
Anamika

I am glad that it helped!

Collapse
 
anarefin profile image
Ahmad Naqibul Arefin

Nice post for beginners.

Collapse
 
noviicee profile image
Anamika

Glad to know it helped!