Exploring Docker Storage Fundamentals
Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).
Objective
In this lab, readers will:
Verify Docker Desktop operation
Download Docker images
Create and manage containers
Understand ephemeral container storage
Create and use Docker volumes
Explore persistent storage
Run a containerized web server
Relate Docker storage concepts to cloud storage technologies
By the end of this lab, readers will understand why persistent storage is important for containers and how Docker volumes work.
Background
Containers are lightweight environments that package applications and their dependencies.
Unlike virtual machines, containers share the host operating system kernel and can start within seconds.
One important concept in containerized environments is storage.
Data stored inside a container may be lost if the container is removed. To preserve data, Docker provides persistent storage mechanisms known as volumes.
This concept is similar to cloud block storage services such as:
AWS Elastic Block Store (EBS)
Azure Managed Disks
Google Persistent Disk
Part 1 – Verify Docker Desktop
Launch:
Docker Desktop
Wait until the status shows:
Engine running
Part 2 – Open PowerShell
Open:
Start
→ PowerShell
Verify Docker:
docker version
Expected result:
Client:
Version: xx.x
Server:
Version: xx.x
Part 3 – Verify Docker Engine
Display running containers:
docker ps
Expected output:
CONTAINER ID IMAGE COMMAND STATUS
No containers are running yet.
Part 4 – Run Your First Container
Execute:
docker run hello-world
Docker automatically:
Downloads the image
Creates a container
Runs the application
Stops the container
Expected output:
Hello from Docker!
Part 5 – Explore Docker Images
Display downloaded images:
docker images
Example:
REPOSITORY TAG
hello-world latest
Discussion:
An image is a template used to create containers.
Examples:
Windows ISO
Virtual machine template
Docker image
Part 6 – Download Ubuntu Image
Download Ubuntu:
docker pull ubuntu
Verify:
docker images
Ubuntu should now appear in the image list.
Part 7 – Start an Ubuntu Container
Launch Ubuntu interactively:
docker run -it ubuntu bash
You are now inside a Linux environment.
Verify:
whoami
Expected:
root
Check operating system:
cat /etc/os-release
Exit container:
exit
Part 8 – Demonstrate Ephemeral Storage
Start a temporary Ubuntu container:
docker run -it ubuntu bash
Create a file:
echo "Temporary Data" > temp.txt
Verify:
cat temp.txt
Exit:
exit
Part 9 – Create Another Ubuntu Container
Launch a completely new container:
docker run -it ubuntu bash
Check for the file:
cat temp.txt
Expected:
cat: temp.txt: No such file or directory
Exit:
exit
Discussion
Why did the file disappear?
Because each new container starts with a fresh writable layer.
This storage is called:
Ephemeral Storage
Data stored only inside the container is temporary.
Part 10 – Create a Docker Volume
Create a persistent volume:
docker volume create cloudplus-volume
Verify:
docker volume ls
Expected:
DRIVER VOLUME NAME
local cloudplus-volume
Part 11 – Verify Empty Volume
Mount the volume into a container:
docker run -it -v cloudplus-volume:/data ubuntu bash
Check contents:
ls /data
Output:
The volume is empty because it has just been created.
Part 12 – Store Data in the Volume
Inside the same container:
echo "Persistent Storage" > /data/storage.txt
Verify:
cat /data/storage.txt
Expected:
Persistent Storage
Exit:
exit
Part 13 – Verify Persistence
Launch a completely new container using the same volume:
docker run -it -v cloudplus-volume:/data ubuntu bash
Check contents:
cat /data/storage.txt
Expected:
Persistent Storage
The file still exists.
Exit:
exit
Discussion
What changed?
The container changed.
The volume remained.
This demonstrates persistent storage.
Part 14 – Inspect the Volume
Display volume information:
docker volume inspect cloudplus-volume
Observe:
Mountpoint
This location stores the actual data.
Part 15 – Run a Web Server
Download and run Nginx:
docker run -d --name webserver -p 8080:80 nginx
Verify:
docker ps
Expected:
webserver
Part 16 – Access the Web Server
Open a browser.
Browse to:
http://localhost:8080
You should see:
Welcome to nginx!
Discussion
Docker is mapping:
Host Port 8080
↓
Container Port 80
This is similar to exposing services in cloud environments.
Part 17 – Explore Docker Desktop
Open Docker Desktop.
Observe:
Images
hello-world
ubuntu
nginx
Containers
Running containers
Stopped containers
Volumes
- cloudplus-volume
Part 18 – Examine Docker Storage Usage
Display storage consumption:
docker system df
Example:
TYPE TOTAL
Images
Containers
Volumes
Build Cache
Observe how Docker consumes storage space.
Part 19 – Cleanup
Stop Nginx:
docker stop webserver
Remove container:
docker rm webserver
Remove volume:
docker volume rm cloudplus-volume
Verify:
docker volume ls
Reflection Questions
What is a Docker image?
What is a Docker container?
What is ephemeral storage?
What is a Docker volume?
Why did temp.txt disappear?
Why did storage.txt remain?
How is a Docker volume similar to AWS EBS?
Why is persistent storage important for databases?
Learning Outcomes
After completing this lab, readers will be able to:
Run Docker containers
Download Docker images
Understand container lifecycle
Demonstrate ephemeral storage
Create Docker volumes
Demonstrate persistent storage
Configure container port mappings
Explore Docker Desktop resources
Relate Docker storage concepts to cloud storage technologies