DevOps Classroom notes 13/Dec/2025

Docker image layers and container

  • Every container gets an virtual disk which is collection of
    • readonly layers (reusable across containers using same image)
    • writable layer (unique for every container)
      Preview
  • For this to workout docker relies on storage driver, as of now overlay driver does this.
  • Any changes from files in readonly layers will be copied into writable layer and then modified.
  • When we delete the container the writable layer also gets deleted i.e. data loss happens.

Solution: Docker volumes

  • figure out the folder where you are storing the data i.e. required (should not be lost)
  • For convienience lets assume the folder is /data
  • We need to ensure this folder lifetime has no dependency on container lifetime.
  • Docker volumes help in creating storages which can have lifetime independent of containers.
  • docker volumes can be created in two ways
    • Mount some folder on docker host into docker container
    • Ask docker to manage this folder

Option 1: Mounting some folder on host into container

  • Create a new folder mkdir /root/data
  • now lets create an alpine container
docker run -d --name alp1 -v /root/data:/data  alpine sleep 1d

Option 2: Create a docker volume and then mount

  • Create a new volume
docker volume create mydata
  • now lets create an alpine container
docker run -d --name alp1 -v mydata:/data  alpine sleep 1d
  • docker volumes with extensions installed can store volumes in aws, azure, or even external locations
  • Docker supports VOLUME instruction in Dockerfile. This instruction automatically creates an anonymous volume if the user doesn’t create explicitly.

Lets create a mysql container

  • command
# create a volume
docker volume create nopdb
# create a mysql contianer
docker run -d \
   -p 33061:3306  \
   --name nopdb \
   -v nopdb:/var/lib/mysql \
   -e MYSQL_ROOT_PASSWORD=admin123 \
   -e MYSQL_DATABASE=nop \
   -e MYSQL_USER=nop \
   -e MYSQL_PASSWORD=nop123 \
   mysql:9
  • Watch classroom recording for next steps
  • Exercise: Repeat the same with postgres db and mongodb in a docker container.

Next Steps

  • Networking
  • optimizations
  • Microservice
  • docker compose

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube