IT 3300 : Virtualization

Docker — Storage

The problem

  • A container's writable layer is ephemeral
  • Remove the container and that data is gone
  • Databases, uploads, logs need to outlive the container

Three ways to persist

  • Volumes — Docker-managed storage (the default choice)
  • Bind mounts — map a specific host path into the container
  • tmpfs — in-memory only, nothing written to disk

Volumes

  • Managed by Docker under its own directory

  • Portable across containers; easy to back up

  • Best for databases and app data

      docker volume create data
      docker run -d -v data:/var/lib/mysql mysql
    

Bind mounts

  • Map a host directory straight into the container

  • Great for development — edit on the host, see it live inside

      docker run -d -v /home/joe/site:/usr/share/nginx/html nginx
    
  • You control the exact host path (and its permissions)

Volumes vs. bind mounts

  • Volume — Docker owns the location; portable; production data
  • Bind mount — you own the path; tied to the host; dev workflows
  • tmpfs — sensitive/scratch data that should never hit disk

Inspecting and cleaning

  • docker volume ls — list volumes
  • docker volume inspect data — where it lives, who uses it
  • docker volume rm data — remove (must be unused)
  • docker volume prune — remove all unused volumes (careful)

Lab goals

  • Run a database with a named volume; write data; recreate the container
    and confirm the data survived
  • Use a bind mount to serve a local folder with nginx and edit it live