top of page

Docker Architecture, Networking, Volumes, Docker Compose, and Troubleshooting Explained with Real-World Examples

Jul 29
4 min read



Introduction


Docker is more than just a tool for running containers. To use Docker effectively in production, you need to understand how its architecture, networking, storage, orchestration, and troubleshooting work together.

Think of Docker as a modern apartment complex:

The Docker Engine is the building manager.

Images are apartment blueprints.

Containers are occupied apartments.

Networks are the roads connecting apartments.

Volumes are personal storage lockers.


Docker Compose is the master plan that builds an entire residential complex with one command.


Docker Architecture

The Docker ecosystem follows a client-server architecture where the Docker Client communicates with the Docker Engine (Daemon) via a REST API.

Component

Function

User/Client

Triggers commands like docker run.

Docker CLI

The primary interface for users.

Docker API

The communication bridge (Socket).

Docker Engine

Manages Images, Containers, Networks, and Volumes.

Host OS & Hardware

The underlying infrastructure.

Docker Client

The Docker CLI is where administrators interact with Docker.

Examples:


docker build

docker run

docker ps

docker stop

Docker Engine

The Docker Engine (dockerd) is responsible for:

  • Building images

  • Running containers

  • Managing storage and networking

  • Pulling images from registries

Think of it as the brain of Docker.


Docker Registry

A registry stores Docker images.

Popular registries include:

  • Docker Hub

  • VMware Harbor

  • Amazon ECR / Azure ACR / Google AR


Example:


docker pull nginx

Docker Image Workflow

  1. Write: Create a Dockerfile.

  2. Build: Run docker build to create an Image.

  3. Ship: Use docker push to store it in a Registry.

  4. Run: Use docker pull and docker run to create a Container.


Docker Networking

Containers need to communicate with:

Other containers

Databases

External users

APIs

The Internet

Docker provides several networking modes.


Bridge Network (Default)

Use case:

Applications running on a single server.

Example:

docker network create app-network


Host Network

In this mode, the container shares the host's networking namespace, providing maximum performance at the cost of network isolation.

Use case:

High-performance networking

Monitoring tools


Overlay Network

Used with:

Docker Swarm

Multi-host environments


Macvlan Network

Useful when containers must appear as physical devices on the LAN.


Docker Port Mapping

Example:

docker run -p 8080:80 nginx

Meaning:


Docker Volumes

Containers are temporary.

If a container is deleted:

Container Deleted

        ↓

Application Data Lost

Volumes solve this problem.


Types of Storage

Named Volume


docker volume create mysql-data

Bind Mount

Host Folder

      │

      ▼

Container Folder

Example:

-v /backup:/data

Anonymous Volume

Automatically created by Docker.

Useful for temporary data.

Real-World Volume Example

A MySQL database stores customer information.

Without a volume:

Container Deleted



Database Lost

With a volume:

Container Deleted



Volume Still Exists



New Container



Database Restored


Docker Compose

Imagine deploying:

Web Server

Database

Redis

API Server

Monitoring

Running five separate docker run commands is inefficient.

Docker Compose allows you to define everything in one file.

Compose simplifies multi-container management. Instead of multiple manual commands, a single docker-compose.yml file defines the entire stack.

Sample Compose File


version: "3.9"

services:

  web:

    image: nginx

    ports:

      - "80:80"

  database:

    image: mysql

    environment:

      MYSQL_ROOT_PASSWORD: Password123

  redis:

    image: redis

Run:


docker compose up -d

Stop:


docker compose down


Docker Compose Benefits

Entire application starts with one command.

Easy development and testing.

Simplified dependency management.

Consistent deployments.

Version-controlled infrastructure.


Docker Troubleshooting

When something goes wrong, use a structured workflow.

Container Not Working

Common Docker Problems

1. Container Exits Immediately

Check:

docker ps -a

Logs:

docker logs container-name

Possible causes:

Wrong command

Missing configuration

Application crash

2. Cannot Pull Image

Example:

Error response from daemon


pull access denied

Check:

Image name

Registry login

Internet connectivity

3. Port Already in Use

Example:

Bind for 0.0.0.0:80 failed

Find the process:

netstat -tulpn

Or change the port:

-p 8080:80

4. Volume Not Mounting

Verify:

docker volume ls

Inspect:

docker volume inspect volume-name

5. Container Cannot Reach Another Container

Check:

docker network ls

Inspect:

docker network inspect app-network

Ensure both containers are attached to the same network.

6. High CPU or Memory Usage

Monitor:

docker stats

Limit resources:

docker run --memory=1g --cpus=2 nginx


Useful Docker Commands


Command

Description

docker ps -a

List all containers (running and stopped).

docker images

List available local images.

docker logs <name>

View container console output.

docker system prune

Cleanup unused data and resources.

Real-World Example

An online shopping platform runs:

Nginx

Java API

MySQL

Redis

Issue: Customers receive "502 Bad Gateway".

Troubleshooting steps:

Verify Nginx is running (docker ps).

Check API container logs (docker logs api).

Confirm API can reach MySQL over the Docker network.

Verify the MySQL volume is mounted and the database is healthy.

Restart only the failed API container after fixing the root cause.

The issue is resolved without affecting the database or Redis containers.

Best Practices

Use official, trusted images.

Keep images small and updated.

Store persistent data in volumes.

Use Docker Compose for multi-container applications.

Create custom networks instead of relying on the default bridge.

Monitor containers with docker stats.

Centralise logs using ELK or Grafana Loki.

Set CPU and memory limits.

Scan images regularly for vulnerabilities.

Avoid running containers as the root user.


Docker vs Kubernetes


Docker

Kubernetes

Builds and runs containers

Orchestrates container clusters

Manual scaling

Automatic self-healing and scaling

Best for local development

Best for production-grade scale


Final Thoughts

Docker provides the foundation for modern application delivery by packaging software into portable containers. Understanding its architecture, networking, storage, Docker Compose, and troubleshooting techniques will help you build reliable, maintainable, and production-ready applications. As environments grow beyond a single host, these Docker concepts become the stepping stones to mastering Kubernetes and cloud-native platforms.

Next in the series: Docker Interview Questions, Best Practices, Security, and Real-World Production Scenarios.


 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page