Understanding Docker: From Installation to Deployment

Shankar ChavhanShankar Chavhan
5 min read

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.

Docker Container vs. Virtual Machine | Download Scientific Diagram

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.

Docker Architecture

Download & Install Docker on Ubuntu?

  1. Update the software repositories

     sudo apt update
    
  2. Install Docker

     sudo apt install docker.io -y
    
  3. Enable and start the Docker service

     sudo systemctl start docker
     sudo systemctl enable docker --now
    
  4. Check Docker version

     docker --version
    

Docker Components?

Docker Engine

Docker Engine is the core component of the Docker, It is consist of.

  1. 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.

  2. 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.

  3. 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

  1. List all running containers

     docker ps
    
  1. List all running and stopped containers

     docker ps -a
    
  2. Start a running container

     docker start container-id
    
  3. Stop a running container

     docker stop container-id
    
  4. Remove a container

     docker rm container-id
    
  5. Remove all stopped containers

     docker container prune
    
  6. View logs of a container

     docker logs container-id
    
  7. Execute a command in running container

     docker exec -it container-id command
    
  8. Attach to a running container

     docker attach container-id
    
  9. Run a container

    docker run -d -p 80:80 --name webserver nginx
    

Docker Images

  1. Build an image from a Dockerfile

     docker build -t image-name
    
  2. List all images

     docker images
    
  3. Remove an image

     docker rmi image-id
    
  4. Tag an image

     docker tag source-image:tag target-iamge:tag
     docker tag node-app:latest node-app:v1.0
    
  5. Push an image to a registry

     docker push image-name
    
  6. Pull an from a registry

     docker pull image-name
    

Docker Networking

  1. List networks

     docker network ls
    
  2. Create a network

     docker network create network-name
    
  3. Inspect a network

     docker network inspect network-name
    
  4. Connect a container to a network

     docker network connect network-name container-id
    
  5. Disconnect a container from a network

     docker network disconnect network-name container-id
    

Docker Volumes

  1. List volumes

     docker volume ls
    
  2. Create a volume

     docker volume create volume-name
    
  3. Inspect a volume

     docker volume inspect volume-name
    
  4. Remove a volume

     docker volume rm volume-name
    
  5. Remove all unused volumes

     docker volume prune
    
  6. 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.

1
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.