Everything you need to know about Docker as a Beginner

Everything you need to know about Docker as a Beginner

ยท

6 min read

Ok so in this blog we are gonna discuss in detail what Docker is all about and what services it provides. But as I did a poll on my Twitter many folks wanted me to separate it into 2 - 3 parts and not make this a lengthy one. So this is going to be the very first part of the Blog which is going to be beginner focused and the next two parts will have more advanced concepts.

So, before talking about Docker one must know what Docker is right? But wait a minute before we jump into that let's understand what are containers.


Also, if you don't wanna read the blog and rather watch a video explaining all these concepts then fear not cause I have a YouTube video up on my channel on this very same topic that you can check out ๐Ÿš€.


๐Ÿฅก What are Containers?

To understand what Containers are let's take a real-world example ( this is my favorite example as this was given by Kelsey Hightower and it made concepts clear ).

Alt Text

So, let's say the holidays are approaching and you want to send some gifts to your loved ones. Here, let's create a scenario of a post office now. They say we can ship your stuff but we don't want you to bring loose stuff like loose books and jewellery rather what you can do is put it all in a box together. So, the box in this case let's say is an envelope.
So depending on how much my envelope weighs and how far I have to send it, the charges are applied and we also add the receiver address on it (i.e. ports in this case).
Now we can fit anything in our envelope it's up to us, you can store applications made in any programming language be it Java, Golang, Ruby etc.
THESE ARE WHAT WE CALL CONTAINERS !!!


๐Ÿณ So how does Docker fit into all this?

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that we discussed above. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.


๐Ÿ“Docker Objects

When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.

Images

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image that is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.

Containers

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state. ( I think we have learned enough about Containers now ๐Ÿ˜‚ )

As this is the first blog that is beginner-friendly in our little Docker Blog series we won't jump into volumes and networks, we will cover these objects later.


๐Ÿณ Let's dive into Docker Architecture

So, Docker Engine is nothing but a host with Docker installed on it and whenever we install Docker Engine on our host we are installing the 3 components that are within the Docker Engine:

Docker Deamon

Docker Deamon works in the background and manages Docker objects such as images, containers, volumes, networks etc.

REST API

The REST API server is an API interface through which users interact with Docker Deamon and provide instructions to it.

Docker CLI

Docker CLI as the name goes means the command-line interface for the Docker that we usually use to run, stop or delete containers, images etc.

๐Ÿ˜ฎ Fun Fact

Docker CLI need not be on the same system as Docker Engine, we could have Docker CLI on a whole other system and work with Docker Engine that is on another system remotely.
All we have to do is use this command to connect our CLI with the engine ๐Ÿ‘‡

docker -H=remote-docker-engine:2375

We just use the -H option followed by the remote address of the engine and a port and Voila!! ๐Ÿš€


๐Ÿค” Hmm, we are making all these images and containers but where are they being stored?

Have you ever wondered when you build and run all these images and containers, where and how they are stored on your Docker Host?
Docker supports several storage drivers, using a pluggable architecture. The storage driver controls how images and containers are stored and managed on your Docker host.
Different storage drivers available are as follows๐Ÿ‘‡:

Well in Docker all the info related to images, volumes, containers etc is stored in /var/lib/docker directory on your machine.
Also to see what storage driver your OS is using you can use this command:

docker info

Like in my case my OS uses an "overlay2" storage driver.

If you're interested in learning more about Docker Storage Drivers, check out their official documentation here.


๐Ÿ“ What is Docker Registry?

The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images. The Registry is open-source, under the permissive Apache license. You can find the source code on GitHub.

Why should I use this registry?

You should use the Registry if you want to:

  • tightly control where your images are being stored

  • fully own your images distribution pipeline

  • integrate image storage and distribution tightly into your in-house development workflow.


๐Ÿ‹ Install Docker on your machine

I'm pretty sure you're eager to get your hands dirty doing some Docker now after reading this amazing blog ๐Ÿ˜‚. Ahm...Ahm enough flattering myself.
Installation of Docker is pretty easy and Docker themselves have a detailed guide on it, make sure to check it out from here and GET STARTED !!!

Press and Media Resources - Docker


Now that you have installed Docker on your machine, let's try some commands so you can get familiar with Docker.

โš’๏ธ Trying out some Docker Commands

  • To see all images that are present on your local machine.
docker images
  • To find out an image on the Docker Hub.
docker search hello-world
  • To download the images from the Docker Hub to your local machine.
docker pull hello-world
  • To give a name to a container.
docker run -it --name <container name> hello-world /bin/bash
  • To start the container.
docker start <container name>
  • To go inside the container.
docker attach <container name>
  • To see all containers.
docker ps -a
  • To see only running containers.
docker ps
  • To stop the container.
docker stop <container name>
  • To delete the container.
docker rm <container name>

Now don't go thinking these are all the commands for Docker cause that would be too easy alright ๐Ÿ˜‚. We have only touched the tip of the iceberg but as this is our very first blog in the series that too beginner friendly we won't go into much detail.

๐Ÿคทโ€โ™‚๏ธ What now?

In the next parts of our Docker series, we'll deep dive into Docker Compose, Docker Swarm, Services and Stacks but for now, you gotta hang tight. Try installing Docker on your machine, pull some images, run some containers and get your hands dirty.
The next part will drop soon...
You can follow me on LinkedIn and Twitter.

ย