DEV Community

Shiivam Agnihotri
Shiivam Agnihotri

Posted on

Docker - Introduction, Architecture, and Most used Commands : Day 5 of 50 days DevOps Tools Series

Introduction

Docker has revolutionised the way we build, ship, and run applications. It enables developers to package applications along with their dependencies into lightweight containers that can run consistently across different environments. In this post, we will dive into Docker’s architecture and cover its basic commands in detail.

Why Docker is Important for DevOps?

Consistency: Docker ensures that applications run the same way in development, testing, and production environments.

Isolation: Containers provide isolated environments for applications, preventing conflicts and improving security.

Scalability: Docker makes it easy to scale applications horizontally by adding more containers.

Efficiency: Containers are lightweight and use system resources more efficiently compared to traditional virtual machines.

Docker Architecture:

Docker Architecture: Image Credit - GeeksForGeeks

Docker architecture consists of the following key components:

Docker Client
Docker Daemon
Docker Images
Docker Containers
Docker Registry

1. Docker Client
The Docker client is a command-line interface (CLI) that allows users to interact with Docker. Users can issue commands such as docker build, docker run, and docker stop through the Docker client.

2. Docker Daemon
The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. It communicates with the Docker client to execute commands.

3. Docker Images
Docker images are read-only templates that contain the instructions to create a Docker container. Images are built using Dockerfiles, which specify the steps needed to create the image.

4. Docker Containers
Containers are runnable instances of Docker images. They are isolated environments where applications run with their dependencies. Containers can be started, stopped, and deleted as needed.

5. Docker Registry
A Docker registry is a storage and distribution system for Docker images. Docker Hub is a public registry, but private registries can also be set up for internal use.

Basic Docker Commands
Now, let's explore the basic Docker commands and their usage.

docker --version: Displays the installed Docker version.

docker --version
Enter fullscreen mode Exit fullscreen mode

docker info: Provides detailed information about the Docker installation, including the number of containers and images.

docker info
Enter fullscreen mode Exit fullscreen mode

docker pull: Pulls an image from a Docker registry.

docker pull <image-name>
Enter fullscreen mode Exit fullscreen mode

docker images: Lists all the Docker images available on the system.

docker images
Enter fullscreen mode Exit fullscreen mode

docker run: Creates and starts a new container from an image.

docker run -it ubuntu
-it: Runs the container in interactive mode with a terminal.
ubuntu: Specifies the image to use.
Enter fullscreen mode Exit fullscreen mode

docker ps: Lists all running containers.

docker ps
Enter fullscreen mode Exit fullscreen mode

To list all containers (running and stopped), use:

docker ps -a
Enter fullscreen mode Exit fullscreen mode

docker stop: Stops a running container.

docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode

docker start: Starts a stopped container.

docker start <container_id>
Enter fullscreen mode Exit fullscreen mode

docker rm: Removes a stopped container.

docker rm <container_id>
Enter fullscreen mode Exit fullscreen mode

docker rmi: Removes a Docker image.

docker rmi <image_id>
Enter fullscreen mode Exit fullscreen mode

docker build: Builds a Docker image from a Dockerfile.

docker build -t my-image:latest .
-t: Tags the image with a name and optional tag (e.g., my-image:latest).
.: Specifies the directory containing the Dockerfile.
Enter fullscreen mode Exit fullscreen mode

docker exec: Runs a command in a running container.

docker exec -it <container_id> /bin/bash
-it: Runs the command in interactive mode with a terminal.
/bin/bash: Specifies the command to run (in this case, starting a bash shell).
Enter fullscreen mode Exit fullscreen mode

docker logs: Fetches the logs of a container.

docker logs <container_id>

Enter fullscreen mode Exit fullscreen mode

docker inspect: Displays detailed information about a container or image.

docker inspect <container_id>

Enter fullscreen mode Exit fullscreen mode

Conclusion
Docker is a powerful tool that simplifies the process of deploying and managing applications in isolated containers. Understanding Docker's architecture and mastering its basic commands are crucial steps for any DevOps engineer. In the next post, we will delve into advanced Docker concepts such as Docker Compose and Docker Swarm.

πŸ”„ Subscribe to our blog to get notifications on upcoming posts.

πŸ‘‰ Be sure to follow me on LinkedIn for the latest updates: Shiivam Agnihotri

Top comments (0)