Day 16: Docker for DevOps Engineers.

Vishal KumarVishal Kumar
5 min read

Docker

Docker is a software platform that allows you to build, test, and deploy applications quickly.

Docker is an open-source containerization platform by which we can pack our application and all its dependencies into a standardized unit called a container.

How docker is important for DevOps engineers?

Docker empowers DevOps engineers to build, deploy, and manage applications more efficiently by providing a consistent, scalable, and standardized platform for software development and deployment.

Docker Architecture

Docker's architecture is designed to provide a flexible, scalable, and efficient platform for building, deploying, and managing containerized applications. It abstracts away the complexities of traditional virtualization and enables developers and operations teams to work with containers easily and effectively.

Here's an overview of the key components:

Docker Engine: At the core of Docker is the Docker Engine, which is a client-server application responsible for building, running, and distributing Docker containers. It consists of three main parts:

  • Docker Daemon (dockerd): The Docker daemon runs on the host system and manages Docker objects such as images, containers, networks, and volumes. It listens for Docker API requests and executes them, handling tasks like container lifecycle management, image distribution, and networking.

  • Docker Client (docker): The Docker client is a command-line interface (CLI) tool used by users to interact with the Docker daemon. Users can use the Docker client to build, run, and manage Docker containers, as well as to communicate with remote Docker daemons.

  • REST API: Docker provides a RESTful API that allows external applications and services to communicate with the Docker daemon. This API enables automation, integration with other tools, and remote management of Docker resources.

Docker Image: A Docker image is a lightweight, standalone, and executable package that contains everything needed to run an application, including the code, runtime environment, libraries, and system tools.

Docker Container: A container is an isolated environment for your code. This means that a container does not know your operating system or your files.

It runs on the environment provided to you by Docker Desktop. This is why a container usually has everything that your code needs to run, down to a base operating system. You can use Docker Desktop to manage and explore your containers.

Docker Registries: Docker registries are repositories for storing and distributing Docker images. Registries can be public or private, and they allow users to share and collaborate on containerized applications. Docker Hub is a popular public registry hosted by Docker, while organizations can set up their own private registries using Docker Registry or other compatible solutions.

Docker life cycle

Docker Container Lifecycle Management is the process of managing the states of Docker containers. It provides a structured framework for managing containers from creation to deletion, enabling developers and operations teams to build, deploy, and maintain containerized applications efficiently.

The Docker Container Lifecycle describes the various stages that occur when we create a Docker container. The stages are:

  • Created: A container that has been created but not started

  • Running: A container running with all its processes

  • Paused: A container whose processes have been paused

  • Stopped: A container whose processes have been stopped

  • Deleted: A container in a dead state

Installing Docker

For downloading docker desktop for window and Mac visit the website:

https://www.docker.com/products/docker-desktop/ or https://docs.docker.com/get-docker/

Some of the basic commands of the docker

docker ps: It is used to list the running containers.

docker ps -a : It is used to list all running and stopped containers.

docker images : It is used to list the local images.

docker login : It is used to login to the account.

docker rmi <image-name> : It is used to delete the image.

docker rm <container-name> : it is used to delete the container.

docker rm -f <container-name> : It is used to delete the running container.

docker -d : It is used to start the docker daemon

docker starts <container-name>: It is used to start the container.

docker stop <container-name> : It is used to stop the running container.

docker run -p <image-name> : It is used to map all the ports.

docker run -d <image-name> : It is used to run the container in the background.

docker exec -it <container-id> : It is used to start a shell inside a running container

docker info : It is used to display system-wide information.

docker pull <image-name>: it is used to download an image.

docker push <image-id>: It is used to upload an image.

docker --help : It is used to get help with docker commands.

Let's do some Hands-on

docker run: It is used to run a docker container.

command: docker run hello-world

docker inspect: It will provide detailed information on the image or container.

command: docker inspect <image-name>

docker port: It is used to check which ports are open on a container.

command: docker port <container_id>

docker stats: It is useful for keeping an eye on the resource utilization of your containers, identifying potential bottlenecks, and troubleshooting performance issues.

command: docker stats <container1><container2>

To come out of the shell press "ctrl+z".

docker top: It provides information about the CPU, memory, and swap usage if you run it inside a Docker container

command: docker top <container_id>

docker save: It is used to save one or more than one image to a tar archive.

command: docker save -o <outputfile.tar> <image_name>

docker load: It loads an image from a tar archive as STDIN, including images and tags.

command: docker load -i <outputfile.tar>

Summary

In this blog, we begin our docker journey which starts with docker and its importance in the life of a DevOps engineer. After that, we learn about the architecture of docker and its lifecycle. We saw some commands that we use mostly in Docker and last we did some hands-on exercises ensuring a practical understanding of Docker's functionality.

6
Subscribe to my newsletter

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

Written by

Vishal Kumar
Vishal Kumar