Docker Fundamentals for Devops

Introduction

Docker is an open-source platform that enables developers to improve application deployment, scaling, and management using lightweight, portable containers. Containerization simplifies the process of building, testing, and deploying applications, enabling teams to work more efficiently and effectively. By reducing the risk of compatibility issues, optimizing resource utilization, and improving security, containerization has become an essential tool for modern software development and DevOps.

In this blog, we will be exploring its fundamental concepts, key components, and even a step-by-step guide on how to install Docker, the benefits of Docker and Docker essential Commands. We will explore the advantages and disadvantages of Docker, its architecture and components, and the basics of working with Docker commands.

What is containerization?

Containerization is a technology used to package and isolate applications along with their dependencies, configuration, and runtime environment. In Docker, it's achieved by creating lightweight, standalone units called containers. Containers provide a consistent and reproducible environment regardless of the underlying infrastructure.

In simple terms, containerization is like putting an application and everything it needs to run into a virtual box. This box, known as a container, has everything required to ensure the application works the same way across different systems.

What is Docker?

To define it in simple terms, Docker is a developer tool to assist developers and system admins in deploying applications in containers to effectively run them in host operating systems like Linux. It’s an overall platform used to develop, ship, and run applications.

Docker Architecture:

  • Images: An image is a read-only template with instructions for creating a Docker container, and run a specific application, including the code, runtime, system tools, and libraries. Docker images are built using a set of instructions specified in a Docker file.

    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.

    Dockerfile: Dockerfile is a simple text file that consists of instructions to build Docker images. It specifies the base image, environment settings, application code, and other configuration options.

    Docker Engine: This is the core component of Docker that provides the runtime environment for containers. It includes a server that runs as a daemon process, a command-line interface for interacting with the daemon, and an API for integrating with other tools and systems.

    Docker Registry: A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is looks for images on Docker Hub by default. You can even run your private registry.

    Docker CLI: This is the command-line interface that developers use to interact with Docker. With the CLI, you can efficiently handle tasks such as creating, starting, stopping, and deleting containers, as well as managing container images, networks, and volumes. The Docker CLI provides a powerful and flexible option for managing containers and their associated resources.

    Docker Compose: Docker Compose is a tool you can use to centrally manage the deployments of many different Docker containers. It allows developers to specify the dependencies between containers and configure the environment variables, volumes, and networks needed to run the application.

Benefits of using Docker:

Portability: Containers encapsulate applications and their dependencies, making them easily portable across different environments, such as development, testing, and production.

Isolation: Containers provide process isolation, which means each container runs in its isolated environment, minimizing conflicts between applications.

Efficiency: Containers share the host system's kernel, which reduces the overhead of running multiple VMs (Virtual Machines) with separate operating systems.

Scalability: Docker makes it simple to scale applications horizontally by spinning up multiple containers of the same image to handle increased traffic.

Consistency: Since containers are based on images, you can ensure consistent behavior in development, testing, and production environments.

Versioning: Docker images and containers can be versioned, making it easier to roll back to previous states or test new releases.

Limitations of Docker:

Networking Complexity: Docker provides networking features for containers, but configuring and managing complex network topologies can be challenging. Inter-container communication and container-to-host communication might require additional setup.

Orchestration Complexity: When dealing with a large number of containers, managing them manually becomes difficult. and developers may need to invest additional time and resources into managing and troubleshooting Docker containers.

Security Isolation: While Docker provides a level of isolation between containers and the host system, it's not as secure as virtual machines (VMs). Containers share the same kernel as the host, which could lead to potential security vulnerabilities. Proper security practices and measures are necessary to minimize these risks.

Size Overhead: Docker images include the application code along with the runtime environment and dependencies. This can result in larger image sizes compared to traditional deployment methods.

Installation of docker :

Just follow the commands given below and you get it installed on your machine.

These are the steps to install docker on your Amazon Linux 2 machine

  1. Update the Package Repository: Before installing any packages, it's recommended to update the package repository to ensure you get the latest versions.

     sudo yum update -y
    
  2. Install Docker: Amazon Linux 2 includes the docker package in its default repositories, so you can simply install it using yum.

      sudo yum install docker
    
  3. Start and Enable Docker: Once Docker is installed, start the Docker service and enable it to start on the system boot.

     sudo systemctl start docker
     sudo systemctl enable docker
    
  4. Add Your User to the Docker Group (Optional): By default, the docker command can only be run by users with root privileges. To avoid using sudo every time you run Docker commands.

     sudo usermod -aG docker $USER
    
  5. Verify Docker Installation: To make sure Docker is installed and working correctly, you can run a simple command to check the Docker version.

     docker --version
    

Check this URL to learn more about the installation of Docker on your host system

Learn More-- >>

Essential Docker Commands:

docker search: This command is used to list only running Docker containers. To search whether images are present in dockerhub or not

docker pull: To download an image from the docker hub to the local machine

docker images: To see all images present in your local machine. This command is used to list all Docker images that are currently available on the local machine.

docker run: This command is used to create and run a new container from a Docker image.

docker ps: This command is used to list only running Docker containers.

docker ps-a: This command is used to list all Docker containers.

docker commit: Use the docker commit command to commit the changes to a new image.

docker login: This command is used to authenticate with a Docker registry.

docker push: This command is used to push a Docker image to a registry/dockerhub.

docker build: This command is used to build a Docker image from a Docker file

docker start: This command is used to start a Docker container.

docker stop: This command is used to stop a running Docker container.

docker rm: This command is used to remove one or more Docker containers.

ensure that before removing the containers we need to stop them

If you want to delete more container then simply use command

docker rm <containername1><containername2><containername3>

docker rmi: This command is used to remove one or more Docker images.

if you want to delete more images then simply use command

docker rmi [image1][image2][image3]like wise.

successfully removed the image [demo_image]

Conclusion

This blog post provides an introduction to containerization using Docker. We discuss the fundamentals of Docker, its pros and cons, the underlying architecture, essential Docker commands, and working with Docker images.

hope this explanation helps you to understand some of the important terminologies in Docker

In closing, I want to say a big thank you to all of you for reading. Your time and engagement mean a lot. I appreciate your support. Let's continue this journey together. Until next time, take care and thanks again!

With gratitude,

Akshay Nazirkar ✨

1
Subscribe to my newsletter

Read articles from Akshay Nazirkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akshay Nazirkar
Akshay Nazirkar