Getting Started with Docker

Getting Started with Docker


6 min read

What is Hypervisor?

A hypervisor is computer software, firmware, or hardware that creates and runs virtual machines. A computer on which a hypervisor runs one or more virtual machines is called a host machine, and each virtual machine is called a guest machine.

What is a virtual machine?

A Virtual Machine (VM) is a computing resource that uses software instead of a physical
computer to run programs and deploy apps. ... Each virtual machine runs its own operating
system and functions separately from the other VMs, even when they are all running on the same host.

What is docker?

Docker is an advanced version of virtualization.

The main work of docker is containerization.

keywords of docker are: develop, ship, and run anywhere.

We can run multiple containers on one host, Container does not have any operating system.

Theory about docker

  • Docker was first released in march 2013, developed by Solomon hykes and Sebastian pahl.
  • Docker is an open-source centralized platform designed to create, deploy and run applications
  • Docker uses a container on the host OS, and runs the application. It allows applications to use the same Linux kernel
  • as a system on the host computer, rather than creating a whole virtual OS
  • We can install docker-engine on any OS, but the docker engine only runs natively on Linux distributions
  • Docker is written in the Go language
  • Docker is a tool that performs OS-level virtualization also called containerization
  • Before docker, many users faced problems that a particular code is running in the developer's system but not in user's
  • Docker is a set of platforms as a service that uses OS level virtualization whereas VMWARE uses hardware-level virtualization.
  • Docker provides a type of platform for our application to be executed.
  • VMWare virtualization: Hardware Level virtualization

    Virtual Machine Virtual Machine Virtual Machine
    OS OS OS

    Docker virtualization

    Ubuntu Container Arch Linux Kali Linux Container
    Docker Engine
    OS- Linux, Ubuntu

    Advantages of Docker

  • No pre-allocation of RAM.
  • CI efficiency:
    Docker enables you to build a container image and use that same image across every steo of the deployment process.
  • Less Cost
  • It is light in weight.
  • It can run on physical hardware/virtual hardware/ or on the cloud.
  • You can re-use the image.
  • It took very less time to create container.
  • Disadvantages of Docker

  • Docker is not a good solution for application that required rich GUI
  • Difficult to manage large amount of containers
  • Docker doesn't provide cross-platform compatability means if an application is designed to run in a docker container on windows, then it can't run on linux or vice-versa.
  • Docker is suitable when the development OS and testing OS are same if the OS is different, we should use VM.
  • No solution for data recovery and backup.
  • Architecture of Docker

  • Developer creates a Dockerfile - Dependencies & required softwares.
  • Execute Dockerfile using docker engine, An image will be created using your Dockerfile.
  • Docker engine will create a container using that image.
  • If we want to share this image, we can upload it to docker hub(Registry).(just like we store our code on github)
  • Anyone want to use image can pull the image from docker hub then docker hub will create an image using the image downloaded from docker hub. And then he can use docker to create a container from that image.
  • Layered file system:
    Container does everything in the form of layers.
  • Components of Docker

    Docker Ecosystem

  • Docker client
  • Docker Hub
  • Docker Daemon or Docker Server or Docker engine
  • Docker images
  • Docker compose
  • Docker Daemon

  • Docker daemon runs on the Host OS.
  • It is responsible for running containers to manage docker services.
  • Docker daemon can communicate with other daemons.
  • Docker Client

  • Docker users can interact with docker daemon through a client.
  • Docker client uses commands and Rest APIs to communicate with the docker daemon.
  • When a client runs any server command on the docker client terminal, the client terminal sends these commands to the docker daemon.
  • It is possible for docker client to communicate with more than one daemon.
  • Docker host(not a part of ecosystem)

  • Docker host is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks and storages.
  • Docker hub/registry

  • Docker registry manages and stores the docker images.
  • Two types of registry in docker
    1. Public Registry: Public registry is also called a docker hub.
    2. Private registry: It is used to share images within the enterprise.
    ### Docker images
  • Docker images are the read-only binary templates used to create docker containers.OR a single file with all dependencies and configurations required to run a program.
  • Ways to create an Image:
    1. Take image from docker hub
    2. Create image from Dockerfile
    3. Create image from existing docker containers
    ### Docker Container
  • Container holds the entire packages that are needed to run the application.OR in other words
    we can say that the image is a template and the container is a copy of that template.
  • Container is like a virtual machine.
  • Images becomes container when they run on the docker engine.
  • Basic commands in docker

  • To see all images present in your local machine
  • $ docker images
  • To find out images in docker hub
  • $ docker search jenkins
  • To download image from dockerhub to local machine
  • $ docker pull jenkins
  • If we want to create a container without running it immediately, we can use the Docker Create command below. bash $ docker container create --name appserver python
  • To give name to container
  • $ docker run -it --name tush ubuntu /bin/bash
    # -it means- interactive mode to terminal
    # run command, creates container and starts it
  • To check service is start or not
  • $ Service docker status
    # $ docker info
    # start docker service
    $ service docker start
    # stop service
    $ service docker stop
  • To start container
  • $ docker start tush
  • To go inside container
  • $ docker attach tush
  • To see all containers
  • $ docker ps -a
  • To see only running containers
  • $ docker ps

    ps - process status

  • To stop container
  • $ docker stop tush
  • To delete container
  • $ docker rm tush

    What is Dockerfile and create container from it, Components & diff command

    Create an image from an existing container

  • Create one container first
  • $ docker run -it --name tushexample ubuntu /bin/bash

  • Inside that container do some work, let's create a file inside tmp directory.
  • $ cd tmp/
    $ touch myfile

  • Exit from this container
  • Now if we want to see the difference between the base image & changes on it then
  • $ docker diff tushexample

  • Create image of this container
  • $ docker commit newcontainer updateimage

  • Check our all images
  • $ docker images

  • Create container from our updated image
  • $ docker run -it --name tushnewcon updateimage /bin/bash

  • Check inside this container our file exists or not.
  • $ ls
    $ cd tmp/
    $ ls

    Did you find this article valuable?

    Support KubeKode Blogs by becoming a sponsor. Any amount is appreciated!