- Intro
- Docker Architecture
- Volumes
- Networking in docker
- Port Mapping
- Layers in docker
- Extras

Intro
- Docker is an open-source software platform that allows you to build, test, and deploy applications quickly using containers.
- It is a tool that performs OS (Operating System) level virtualization, also known as containerization.
- You can install and run docker engine on any OS.
- How docker works on a host machine:Hardware —>OS —> Docker Engine —> Run the container
- When you fetch any Docker image from the Docker Hub, you’re getting all the necessary user-space files for that container’s environment. Then at runtime, Docker attach those files to the host’s OS kernel (Linux kernel, or Windows kernel for Windows containers).
Docker Architecture
Docker Engine:
- It’s a client-server application that provides code functionality to build, run and manage lifecycle, networking, storage and other aspects of docker contaienrs.
- It has 2 parts: Docker Daemon(server)CLI (client)
- Docker Daemon can communicate with other daemons.
- Docker client uses REST Api to communicate with the Docker daemon.
- When a client runs any server commands on the Docker client terminal, the client terminal sends these Docker commands to the Docker daemon.
- It is possible for Docker client to communicate with more than one daemon.
Docker Image:
- Docker images are the read only binary templates used to create Docker containers. Or, Single file with all dependencies and configuration required to run a program including the code, runtime, libraries, dependencies, and system tools. It is created from a set of instructions defined in a Dockerfile and can be used to create Docker containers.
- Ways to create Docker Images: Take image from Docker Hub.Create image from Docker file.Create image from existing Docker containers.
- Take image from Docker Hub.
- Create image from Docker file.
- Create image from existing Docker containers.
- To build a Docker image using a Dockerfile, you use the docker build command followed by the path to the directory containing the Dockerfile.
Containers:
- A container is a running instance of an image. If an image is the template, a container is the exact copy of template but in running form.
- Images becomes container when they runs on Docker engine.
- It is created from a set of instructions defined in a Dockerfile and can be used to create Docker containers.
- Containers are like virtual machines, but they are isolated from each other and from the host system but share the host’s kernel, which makes them lighter than virtual machines.
- How Containers are different from virtual machines?
- It is impossible to lose any data as long as a container exists. Until the said container is deleted by you
Docker Registry:
- There are two types of registries in the docker. Public Registry: It is also known as Docker Hub. Anyone can use this to fetch images.Private Registry: It is used to share Docker images within the organisation.
- Public Registry: It is also known as Docker Hub. Anyone can use this to fetch images.
- Private Registry: It is used to share Docker images within the organisation.
- Docker Hub is a cloud-based registry provided by Docker that allows developers to store, share, and distribute Docker images. It provides a central repository of public and private Docker images. This makes it easy to discover and access pre-built images created by the Docker community and other organizations.
Volumes
- Volume is simply a directory inside our container, but not a normal directory but storage.
- Firstly, we have to declare the directory as a volume and then share the volume.
- Even if we stop the container, still we can access the volume.
- Volume will be created in one container and share with as many container as possible.
- You can declare a directory as a volume only while creating container.
- You can’t create volume from existing container.
- Volume will not be included when you update an image.Benefits of Volume
- You can map volume in two ways: Container to ContainerHost to Container On deleting containers, volume is not deleted
- Container to Container
- Host to Container On deleting containers, volume is not deleted
- On deleting containers, volume is not deleted
- Decoupling container from storage (meaning no relation between container and storage)
- Share volume among different containers
- Attach volume to containers
Networking in docker
Docker Networking Basics
Docker networking enables containers to communicate with each other, the host machine, and external networks while maintaining isolation. Each container runs in its own network namespace, which includes separate IP addresses, routing tables, and interfaces, preventing conflicts with the host or other containers.
Default Bridge Network
Docker creates a default bridge network called "docker0" upon installation, automatically connecting new containers to it unless specified otherwise. Containers on this network can communicate using IP addresses but not by name, and they access the internet via port mapping from container ports to host ports.
User-Defined Networks
Create custom networks with docker network create -d bridge my-net to allow containers to resolve each other by name and IP within the same network. This isolates groups of containers, such as frontend and backend services, improving security and organization.
Network Types
- Bridge: Default for single-host setups; containers share a subnet and communicate internally.
- Host: Container shares the host's network stack directly, bypassing isolation for better performance but risking port conflicts.
- None: Fully isolates the container with no external network access.
- Overlay: Enables multi-host communication in Docker Swarm clusters using VXLAN encapsulation.
Key Commands
Use docker network ls to list networks, docker run --network=my-net to attach a container at startup, or docker network connect my-net container-name for running containers. Containers can join multiple networks for flexible communication across segments.
Port Mapping
Port mapping in Docker connects a port on your host machine (like your computer) to a port inside a running container, allowing external access to services inside the container. Containers run in isolated network spaces, so without mapping, you can't reach apps like a web server from outside. Docker uses the -p flag with docker run to create this bridge via Network Address Translation (NAT)
Basic Syntax
Use docker run -p host_port:container_port image_name to map ports.
- Host port: The one accessible on your machine (e.g., 8080).
- Container port: Where the app listens inside (e.g., 80).
Layers in docker
Docker layers are read-only snapshots of filesystem changes created by each instruction in a Dockerfile, stacked together to form a complete image efficiently
How Layers Form
Each Dockerfile command like RUN, COPY, or ADD creates a new layer capturing only the differences (additions, deletions, or modifications) from the previous state. Layers are immutable once built, enabling Docker to cache and reuse them across images for faster builds. For example, starting from a base image like alpine:latest, a RUN command to install Node.js adds just those changed files as a new layer on top.
Union Filesystem
Docker uses a union filesystem to stack layers, merging them into a single unified view without copying files between them. When running a container, a temporary read-write layer sits on top, allowing runtime changes that vanish on stop. This design saves storage since shared base layers (e.g., from popular images) are stored once.
Extras
- The docker exec command is used to run a command within a running Docker container. It provides a way to execute commands inside a container's environment such as running a shell, running scripts, or interacting with running processes.
- Docker allows you to limit the CPU and memory usage of a container using resource constraints. You can set the CPU limit with the --cpu option and the memory limit with the --memory option when running the container using the docker run command.
- Multi-stage builds in Docker allow you to create optimized Docker images by leveraging multiple build stages. Each stage can use a different base image and perform specific build steps. To create a multi-stage build, you define multiple FROM instructions in the Dockerfile, each representing a different build stage. Intermediate build artifacts can be copied between stages using the COPY --from instruction. This technique helps reduce the image size by excluding build tools and dependencies from the final image.
- There are several techniques to debug issues in a Docker container:Logging: Docker captures the standard output and standard error streams of containers, making it easy to inspect logs using the docker logs command.Shell access: You can access a running container's shell using the docker exec command with the -it option. This allows you to investigate and troubleshoot issues interactively.Image inspection: You can inspect the Docker image's contents and configuration using docker image inspect. This lets you check for potential misconfigurations or missing dependencies.Health checks: Docker supports defining health checks for containers, allowing you to monitor the health status and automatically restart or take action based on predefined conditions.
Commands
- docker rm mycontainer will remove a container named mycontainer
- **Docker start mycontainer** will start a container named mycontainer.
- Docker stop mycontainer will stop the container
- docker build -t myimage:tag will build an image named myimage with the specified tag using the Dockerfile in the current directory.
- **docker run myimage:tag** will create and start a new container based on the specified image.
- prune docker system $ Prune is a command that gets rid of all of your stopped containers, unused networks, caches, and hanging images
- docker image inspect myimage will display detailed information about the specified image including its tags, layers, size, creation date, exposed ports, environment variables, and more. The output is in JSON format which allows you to extract specific fields programmatically.
- docker exec -it mycontainer bash opens a shell session within the container named mycontainer.
- **docker run --cpu 2 --memory 1g mycontainer** limits the container to use a maximum of 2 CPU cores and 1GB of memory
to interact with this post.
Topics included
Social.
Snapshot.
Instantly create a share-worthy social post for this post.
Explore similar content
The Engineering Problems Docker Solves
These days almost every software developer has come to know about Docker. In fact, most people use it in their software development journey. Almost everyone knows about Docker—how to write a Dockerfile, how to write a Docker Compose file, how to push or pull images, how to reduce image size, how to configure Docker networks, persistent volumes, Docker commands, etc.
Monitoring Docker Containers with Prometheus, Grafana and cAdvisor
To operate Docker workloads reliably, you need resource visibility and data persistence. This setup adds:
Mastering Multi-Stage Dockerfiles: Build Smaller, Faster & Production-Ready Images
Shipping applications in Docker is easy — but shipping lightweight, secure, and optimized images is where the real DevOps skills shine. That’s exactly what Multi-Stage Dockerfiles help you achieve.
The Ultimate Guide to Grafana: What It Is, Why It’s Used, and How to Build a Complete Monitoring Stack with Prometheus, Node exporter and Docker
Modern infrastructure generates thousands of data points every second—metrics, logs, traces, events, service health, and user activity. For DevOps teams, monitoring all of this in real time is crucial.
Invoking APIs from One Docker Container to Another
Docker is a powerful tool that allows you to encapsulate your application and its dependencies into a standardized unit for software development. One common scenario when using Docker is the need to invoke APIs running on one Docker container from another Docker container. This article will guide you through the process step by step.
Set up a reverse proxy using Nginx to route requests to multiple backend apps
Before diving into setting up a reverse proxy with Nginx, it's essential to first understand what a reverse proxy is. To effectively use Nginx as a reverse proxy, we need to clear any confusion around the concept of reverse proxies.





