🐋Day 19: Docker Guide for DevOps Engineers

🐋Day 19: Docker Guide for DevOps Engineers

🐋Day 19: Docker Guide for DevOps Engineers

✅Table of Content

🐋What is Docker?

🐬Docker Architecture

🐋Advantages of Docker

🦭Disadvantages of Docker

🐟Docker Components

🐳Docker Commands

🎉Conclusion:

🐋What is Docker?

Docker: Your Software Superhero! 🦸‍♂️🐳

Docker is an open-source platform that automates the deployment of applications inside lightweight, portable containers. Containers can run on any system that supports Docker, providing consistency across multiple development and release cycles.

🐋Docker Architecture :

  • Docker is an open-source centralized platform designed to create, deploy and run application.

  • Docker uses container on the host OS to run applications. 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 on any OS but docker engine runs natively on Linux distribution.

  • Docker written in 'go' language.

  • Docker is a tool that performs OS level virtualization, also known as containerization.

  • Before docker, many users faces the problem that a particular code is running in the developer's system but not in the user's system.

  • Docker was first release in "March 2013". It is developed by "Solomon Hykes" and "Sebastian Pahl".

  • Docker is a set of platform as a service that uses OS level virtualization whereas VMware uses hardware level virtualization.

🐋Advantages Of Docker :

  • No pre-allocation of RAM.

  • CI (Continuous Integration) efficiency: Docker enable you to build a container image and use that same image across every step of the deployment process.

  • Less cost & light in weight.

  • It can run on physical H/w / Virtual H/w or on 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 requires rich GUI.

  • Difficult to manage large amount of containers.

  • Docker does not provide cross-platform compatibility, 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 & backup.

🐋Components of Docker :

  1. Docker Daemon
  • Docker daemon run on that Host OS.

  • It is responsible for running containers to manages docker services.

  • Docker daemon can communicate with other daemon.

  1. Docker Client
  • Docker users can interact with docker daemon through a client.

  • Docker client uses command and Rest API to communicate with the docker daemon.

  • When a client runs any server command on the docker client terminal, the client terminal sends these docker commands to the docker daemon.

  • It is possible for docker client to communicate with more than one daemon.

  1. Docker Host

    Docker Host is used to provide an enviroment to execute and run applications. It contains the docker daemon, images, containers, networks and storages.

  2. Docker HUB / Registry

    Docker registry manages and stores the docker images. These are two types public and private.

  3. Docker images

  • Docker images are the read only binary templates used to create docker container.

  • Single file with all dependencies and configuration required to run a program.

  1. Docker Container
  • We can say that the images is a template and the container is a copy of that template.

  • Container is like a Virtual Machine.

  • Image becomes container when they run on docker engine.

  1. Docker file

    Docker file is basically a text file. It contains some set of instructions.

Let's go through some basic Docker commands to get you started.

🐋Basic Docker Commands :

  1. Update the package index

       sudo apt-get update -y
    
  2. Install the latest version of Docker

       sudo apt-get install docker.io -y
    
  3. Check docker version

       docker --version
    
  4. Check status of docker service

       sudo service docker status
       OR
       systemctl status docker
    

    press "q" for exit.

  5. To see all images present in your local machine.

       sudo docker images
    
  6. Give permission to docker user to run docker commands without "sudo".

       sudo usermod -aG docker $USER
    
  7. Now check docker user added or not in group at last line.

       cat /etc/group
    
  8. Now restart your instance.

       sudo reboot
    

    It take few minutes to restart or you can connect your instance again.

  9. Again see all images present in your local machine.

       docker images
       OR
       docker images ls
    
  10. To see running container.

    docker ps
    
  11. To see all container active or inactive.

    docker ps -a
    
  12. To find out images in docker hub.

    docker search <image name>
    
  13. To download image from docker hub to local machine.

    docker pull <image name>:tag
    
  14. To create and run container by giving name using docker hub image.

    -it = interactive terminal

    docker run -it --name <container name> <image name> /bin/bash
    
  15. To exit from container.

    exit 
    or
    Ctrl+c
    
  16. To start container.

    docker start <container ID / Name>
    
  17. To go inside container.

    docker attach <container name>
    
  18. To stop container.

    docker stop <container name>
    
  19. To delete stop container.

    rm = remove

    docker rm <container name>
    
  20. To remove a local image.

    docker rmi <imagename>:tag
    
  21. To tag an image.

    docker tag <sourceimage>:tag <newimage>:tag
    
  22. Build an image from dockerfile.

    docker build -t <imagename> path_of_Dockerfile
    
  23. Push an image to docker hub.

    docker push <image_name>:tag
    
  24. Inspect details of an image.

    docker image inspect <image_name>:tag
    
  25. Save an image to tar archive.

    docker save -o <image_name>.tar <image_name>:tag
    
  26. Load an image from tar archive.

    docker load -i <image_name>.tar
    
  27. Prune unused images.

    docker images prune
    
  28. To view container logs

    docker logs <container_name/ID>
    

🐋Conclusion :

Docker provides vital commands for effective container oversight. Users manage containers (docker run), inspect details (docker inspect), handle port mappings (docker port), monitor resources (docker stats), observe processes (docker top), and export/import images (docker save/docker load). These tasks enhance container orchestration, guaranteeing smooth application deployment and monitoring.

Happy Learning !😊