Understanding Docker: From Installation to Deployment
Why Docker?
Previously, when a developer or system administrator needed to create a logical server on a physical server, they would use virtualization software to create a logical server from the physical server.
In this approach, logical resources were often wasted. For example, if an application required 1GB of space to run and I allocated 2GB for the logical server, 1GB of space would be wasted.
To solve this issue, the IT industry introduced a new concept called containerization. With containerization, you don't need to create a logical server from your physical server. Instead, you can install Docker Engine on your physical server and run your application as a container. The container will use the necessary binaries and libraries from the hardware or kernel.
This is why we started using Docker. Docker allows applications to run in containers, which are lightweight and portable.
Virtual Machine vs Docker Containers?
Virtual Machine is logical server created on top of the physical server by using a Hypervisor software called Oracle VirtualBox, Xen etc.
Virtual Machine consume the computing resources from physical server. If you delete the virtual machine all resources are release.
Docker Container is a lightweight, standalone, executable packages that include everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings.
What is Docker?
Docker is a platform that enables developers to build, ship, and run applications inside lightweight, portable containers. Containers allow developers to package an application with all its dependencies into a standardized unit for software development.
Architecture of Docker?
Docker uses a client-server architecture. The Docker client communicates with the Docker daemon, which builds, manages, and distributes your Docker containers.
A Docker client can also be connected to a remote Docker daemon, or the daemon and client can operate on the same machine. They communicate over a REST API, over UNIX sockets, or a network interface.
A Docker registry has Docker images stored in it. The most popular public Docker registry is the Docker Hub which anyone can use.
Download & Install Docker on Ubuntu?
Update the software repositories
sudo apt update
Install Docker
sudo apt install docker.io -y
Enable and start the Docker service
sudo systemctl start docker sudo systemctl enable docker --now
Check Docker version
docker --version
Docker Components?
Docker Engine
Docker Engine is the core component of the Docker, It is consist of.
Docker Daemon
The Docker Daemon runs on the host machine and is responsible for building, running, and managing Docker containers. It is also known as dockerd.
Docker Client
he Docker Client is a command-line interface (CLI) tool that allows users to interact with the Docker Daemon. Users can issue commands such as docker run and docker build through the Docker Client. It is also known as docker.
REST API
Docker Engine uses a REST API to communicate between the Docker Daemon and the Docker Client, enabling programmatic control of Docker.
Docker Containers
List all running containers
docker ps
List all running and stopped containers
docker ps -a
Start a running container
docker start container-id
Stop a running container
docker stop container-id
Remove a container
docker rm container-id
Remove all stopped containers
docker container prune
View logs of a container
docker logs container-id
Execute a command in running container
docker exec -it container-id command
Attach to a running container
docker attach container-id
Run a container
docker run -d -p 80:80 --name webserver nginx
Docker Images
Build an image from a Dockerfile
docker build -t image-name
List all images
docker images
Remove an image
docker rmi image-id
Tag an image
docker tag source-image:tag target-iamge:tag docker tag node-app:latest node-app:v1.0
Push an image to a registry
docker push image-name
Pull an from a registry
docker pull image-name
Docker Networking
List networks
docker network ls
Create a network
docker network create network-name
Inspect a network
docker network inspect network-name
Connect a container to a network
docker network connect network-name container-id
Disconnect a container from a network
docker network disconnect network-name container-id
Docker Volumes
List volumes
docker volume ls
Create a volume
docker volume create volume-name
Inspect a volume
docker volume inspect volume-name
Remove a volume
docker volume rm volume-name
Remove all unused volumes
docker volume prune
Mount a volume to a container
docker run -d -v volume-name:/path/in/container image docker run -d -v myvolume:/app/data nginx
Docker Hub
Docker Hub is a cloud-based registry service for storing and sharing Docker images. It provides a central repository where users can find, publish, and manage Docker images. Docker Hub includes both public and private repositories.
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file (docker-compose.yml) to configure the application's services, networks, and volumes. With a single command (docker-compose up), users can start all the services defined in the Compose file.
Docker Swarm
Docker Swarm is Docker's native clustering and orchestration tool. It allows users to create and manage a swarm of Docker nodes (a cluster of Docker engines) and deploy services across the swarm. Swarm provides features for service discovery, load balancing, scaling, and rolling updates.
Docker Registry
A Docker Registry is a storage and distribution system for Docker images. Docker Hub is the default registry, but users can also set up their own private registries using Docker Registry, an open-source implementation of the Docker Registry API.
Dockerfile
A Dockerfile is a text file that contains a series of instructions on how to build a Docker image. It includes commands to specify the base image, copy files, install dependencies, set environment variables, and define the container's startup command.
Conclusion
Docker is a platform that simplifies application development and deployment by using containers for consistency and efficiency. Key components include Docker Engine, Docker Images, Docker Containers, Dockerfile, Docker Hub, Docker Compose, Docker Swarm, Docker Volumes, Docker Network, and Docker Registry. Docker can be installed on Ubuntu via APT, a convenience script, or Snap. A comprehensive cheat sheet provides essential commands for managing containers, images, networks, and volumes.
Subscribe to my newsletter
Read articles from Shankar Chavhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Shankar Chavhan
Shankar Chavhan
I'm a Cloud DevOps Engineer passionate about automating infrastructure and enhancing development workflows. Experienced in AWS, Docker, Kubernetes, and CI/CD pipelines, I focus on creating efficient, scalable, and secure cloud solutions. I enjoy teaching AWS and sharing insights on DevOps practices. Follow my blog for tips on cloud computing and DevOps tools.