Docker Volumes for Persistence
Implement Docker volumes to store and manage persistent data for your containerized applications.
Docker Volumes for Persistence is a free Docker & DevOps Fundamentals lesson on CoddyKit — lesson 2 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.
Why Persistent Data?
Containers are designed to be light and temporary. When a container is removed, any data stored inside its writable layer is lost forever.
But what if your application needs to save important information, like a database or user files? This is where data persistence comes in!

Introducing Docker Volumes
Docker Volumes are the best way to store application data persistently in Docker. Unlike data stored directly in a container, volumes are managed by Docker and exist independently of any specific container.
- They are stored in a part of the host filesystem managed by Docker.
- They are optimized for I/O performance.
- They are easy to back up or migrate.
Create Your First Volume
Let's create a named volume. Named volumes are simple: you give them a name, and Docker handles the rest.
Use the docker volume create command, followed by your desired volume name.
docker volume create my_data_volumeList Your Volumes
After creating a volume, you can see it listed among all existing Docker volumes on your system.
Use the docker volume ls command to view them.
docker volume lsUse Volume with a Container
Now, let's run a container and attach our newly created volume to it. We use the -v flag for this.
The format is -v volume_name:container_path. This mounts my_data_volume to /app/data inside the nginx container.
docker run -d --name my_app_with_volume -v my_data_volume:/app/data nginxStore Data in the Volume
Let's write some data into the mounted volume from inside our running container. We'll use docker exec to run a command inside the container.
The data will be saved at /app/data/message.txt within the container, which is actually stored in my_data_volume.
docker exec my_app_with_volume sh -c "echo 'Hello from CoddyKit!' > /app/data/message.txt"Data Survives Container Removal
The key benefit of volumes: data persistence! Let's prove it.
First, we'll stop and remove our container. Then, we'll run a *new* container, attaching the *same* volume to read the data we wrote.
docker stop my_app_with_volume
docker rm my_app_with_volume
docker run --rm -it -v my_data_volume:/app/data alpine sh -c "cat /app/data/message.txt"Inspect Volume Details
You can get detailed information about a volume using the docker volume inspect command. This shows its name, driver, and importantly, its mount point on the host filesystem.
docker volume inspect my_data_volumeCleaning Up Volumes
Remember, volumes live independently of containers. If you no longer need a volume, you must explicitly remove it.
Use docker volume rm. Be careful, as this permanently deletes the data!
docker volume rm my_data_volumeQuick Check on Volumes
Time for a quick question to test your understanding of Docker Volumes!
Volumes: Key to Persistent Data
Great job! You've learned how Docker Volumes provide a robust solution for persistent data storage.
- Volumes keep your data safe, even if containers are removed.
- They are managed by Docker, offering better performance and portability.
- You can create, list, inspect, and remove them with simple commands.
Next, we'll explore Bind Mounts, another way to manage data, but with different use cases.
Frequently asked questions
Is the “Docker Volumes for Persistence” lesson free?
Yes — the full text of “Docker Volumes for Persistence” 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 “Docker Volumes for Persistence”?
Implement Docker volumes to store and manage persistent data for your containerized applications. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Docker Volumes for Persistence” 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
- Container Networking Basics
- Docker Volumes for Persistence
- Bind Mounts and tmpfs Mounts
- Custom Bridge Networks and Service Discovery