Getting Started with Docker

Getting Started with Docker

What is Docker?

Docker is an open-source containerization platform. it enables developers to package applications into containers. A developer defines all the dependencies of an application in a Dockerfile Which defines the Docker image and that image defines Docker containers. Make sure your application will run in any environment.

Install docker from here.

Why use Docker?

Using Docker you can quickly ship your code faster with minimum compute resources(RAM, CPU, Networking etc). You can deploy the application on containers that make it easier to be deployed, scale, and manage. it is used for Microservices, Data processing, and CI/CD Processes as well.

Virtualization vs Containerization

VirtualizationContainerization
It's a Hardware virtualization. If an Application runs on a virtual machine it requires a guest OS and underlying hypervisor. A hypervisor is software that creates, runs, and manages a virtual machine. These virtual machines have their operating system and don't use the host OS. They need some computing resources to allocate.Containerization means OS Virtualization. Containerization is an efficient way of deploying applications. its a lightweight in use. A container includes all the necessary dependencies in docker images that define the container to run an application. It enables multiple containerized applications to run independently on a single host system.


Docker Architecture

Docker uses Client-Server architecture, which includes three main components that are Docker Client, Docker Host, and Docker Registry.

  1. Docker Client

This is what you use to interact with Docker to communicate with the Docker daemon. When a client runs any docker command on the docker client terminal, the client terminal sends these docker commands to the Docker daemon. The Docker daemon receives these commands from the Docker client in the form of commands and REST API requests.

$ docker build <Image_name>
$ docker run <Image_name>
$ docker pull <Image_name>
  1. Docker Host

It is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks, and storage.

  • Docker daemon:

    It listens to the APl request being made by the docker client and manages Docker objects such as images, containers, networking, and storage. Docker daemon communicates with other daemons. It offers various Docker objects such as images, containers, networking, and storage.

  • Docker File:

    Dockerfile is a step to create a docker image. it is like a recipe with all ingredients and steps necessary in making your dish which means To create an image of your application, you will require its version, programming language, and corresponding commands. All of these instructions are stored in the Dockerfile to facilitate the creation of a Docker image.

    1. Create a file named Dockerfile

    2. Put all the necessary instructions in Dockerfile

    From ubuntu
    MAINTAINER samyakseokar@gmail.com

    RUN apt-get update
    RUN apt-get install -y nginx
    CMD ["echo", "thi is Dockerfile"]
  1. This is a Dockerfile meant for a real-world Python Django application.
    From python:3
    RUN pip install django==4.1.4  #depends on the application version
    copy . .
    RUN python manage.py migrate
    EXPOSE 8000  #It Expose a port no.
    CMD["python", "manage.py", "runserver", "0.0.0.0:8000"]
  1. By default, Docker searches for the Dockerfile when building $docker build -t imagename:1.0 .

  2. You can upload your docker image to your docker hub, making it available for others to use. $docker push <imagename>

  • Docker image:

    A Docker image is a file that defines a Docker container. A container can move from one environment to another with the same OS because all the necessary dependencies required for running the code are included in the image.

    Basic Commands

      $ docker pull ubuntu:18.04 #18.04 is tag/version
      $ docker images #list docker Images
      $ docker run imagename #create container
      $ docker rmi imagename #delete a docker image
      $ docker rmi $(docker images -q) # it deletes all docker images
    
  • List Containers:

      $ docker ps -a
      CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS
      4183618bcf17   ubuntu:18.04   “/bin/bash”   4 minutes ago   Exited
    
  1. Docker Registry

    A Docker registry is a central storage location for distributing Docker images also known as a Docker hub. The most common registry is Docker Hub, where developers can publish their images for others to use. Private registries can also be set up; however, Docker is configured to look for images on Docker Hub by default.

    When you use docker pull or docker run commands, Docker automatically retrieves the necessary images from the registry you have configured. On the other hand, when you use docker push, the image you specify gets uploaded to your configured registry.

docker pull <Image_Name>
docker run  <Image_Namw>
docker push <Image_Name>
  1. Docker Swarm

    A Docker Swarm is a container orchestration tool running the Docker application. It is used for managing, scaling, and management of containerized applications. The activities of the cluster are controlled by a swarm manager.

  2. Docker Compose

    Docker Compose is a tool that handles multiple containers at once. Docker-compose is for running multiple containers as a single service. It does so by running each container in isolation but allowing the containers to interact with one another.

Thank you so much for taking your valuable time to read

After being inspired by Kunal Kushwaha and his tutorials, I decided to take the initiative to learn in public and share my work with others. I made an effort to present the information in a simple and concise manner. I hope that you were able to learn something new from my work today.

We welcome any feedback that can help us improve. Thank you!