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 consists of the following key components:
Docker Client
Docker Daemon
Docker Images
Docker Containers
Docker Registry
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.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.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.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.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
docker info: Provides detailed information about the Docker installation, including the number of containers and images.
$ docker info
docker pull: Pulls an image from a Docker registry.
$ docker pull
docker images: Lists all the Docker images available on the system.
$ docker images
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.
docker ps: Lists all running containers.
$ docker ps
To list all containers (running and stopped), use:
$ docker ps -a
docker stop: Stops a running container.
$ docker stop
docker start: Starts a stopped container.
$ docker start
docker rm: Removes a stopped container.
$ docker rm
docker rmi: Removes a Docker image.
$ docker rmi
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.
docker exec: Runs a command in a running container.
$ docker exec -it /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).
docker logs: Fetches the logs of a container.
$ docker logs
docker inspect: Displays detailed information about a container or image.
$ docker inspect
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.
Top comments (0)