0Pricing
Docker & DevOps Fundamentals · Lesson

Managing Data with Docker Volumes

Understand why containers lose their data on removal and learn how to persist and share data using Docker volumes and bind mounts.

Managing Data with Docker Volumes is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Docker & DevOps Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Containers Are Ephemeral

Containers are ephemeral: anything written lives inside the container, and removing it wipes the data. Fine for stateless apps, but a database needs its data to survive.

The Writable Layer

Each container has a thin writable layer on top of its image. Writes land there, but it's tied to the container's life — delete the container and that layer vanishes.

Two Ways to Persist Data

Docker offers two ways to persist data: volumes (managed by Docker) and bind mounts (a host folder mapped in). Volumes are the recommended default.

Creating a Volume

Create a named volume in one command with docker volume create. Docker decides where it physically lives so you don't have to.

docker volume create app-data

Mounting a Volume

Attach a volume with -v using volumeName:/path/in/container. Now everything written to that path persists in the volume.

docker run -d -v app-data:/var/lib/data myimage

Data Survives Removal

Since the volume is independent of the container, you can delete the container, spin up a new one with the same volume, and your data is still there.

docker rm -f mycontainer
docker run -d -v app-data:/var/lib/data myimage

Bind Mounts for Local Development

A bind mount maps a host directory into the container — perfect for development, where editing code on your machine shows up instantly inside.

docker run -v /Users/me/project:/app node:20

Volumes vs Bind Mounts

Pick by the job: volumes for portable, Docker-managed production data; bind mounts for development when you want an exact host path and full control.

Inspecting Volumes

docker volume ls lists your volumes and docker volume inspect shows details — including where the data actually lives on disk.

docker volume ls
docker volume inspect app-data

Sharing Data Between Containers

Mount one volume into multiple containers and they share files — for example, an app container and a backup container both reading the same data.

docker run -v shared:/data writer
docker run -v shared:/data reader

Cleaning Up

Unused volumes waste disk. Remove one with docker volume rm or clear dangling ones with docker volume prune — carefully, since this deletes data for good.

docker volume rm app-data
docker volume prune

Quick Check

Test your understanding of Docker data.

Recap

You learned to persist data: containers are ephemeral, volumes survive removal and mount with -v name:/path, while bind mounts suit development.

Frequently asked questions

Is the “Managing Data with Docker Volumes” lesson free?

Yes — the full text of “Managing Data with Docker Volumes” is free to read here on the web, and the Docker & DevOps Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Docker & DevOps Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Managing Data with Docker Volumes”?

Understand why containers lose their data on removal and learn how to persist and share data using Docker volumes and bind mounts. You practise Docker & DevOps Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Docker & DevOps Fundamentals?

No prior experience is required. Docker & DevOps Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Managing Data with Docker Volumes” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Docker & DevOps Fundamentals lesson?

Yes. Every Docker & DevOps Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What are Containers?
  2. Installing Docker Desktop
  3. Your First Docker Container
  4. Managing Data with Docker Volumes
← Back to Docker & DevOps Fundamentals