0
0
Dockerdevops~30 mins

Creating and managing volumes in Docker - Try It Yourself

Choose your learning style9 modes available
Creating and managing volumes
📖 Scenario: You are working on a Docker project where you need to store data persistently outside of containers. This means even if a container is deleted, the data remains safe. Docker volumes help with this by providing a special storage area on your computer.In this project, you will create a Docker volume, use it in a container, and then check the volume's data to understand how volumes work.
🎯 Goal: Learn how to create a Docker volume, attach it to a container, write data inside the container to the volume, and verify the data persists after the container is removed.
📋 What You'll Learn
Create a Docker volume named mydata
Run a container using the busybox image with the volume mydata mounted at /data
Inside the container, create a file named hello.txt with the content Hello, Docker Volumes!
Verify the file exists in the volume by running another container and reading the file
Remove the first container and confirm the volume still holds the data
💡 Why This Matters
🌍 Real World
Docker volumes are used in real projects to keep databases, logs, and user files safe even when containers are updated or removed.
💼 Career
Understanding Docker volumes is essential for DevOps roles to manage persistent data in containerized applications reliably.
Progress0 / 4 steps
1
Create a Docker volume named mydata
Type the command to create a Docker volume called mydata.
Docker
Need a hint?

Use the docker volume create command followed by the volume name.

2
Run a container with the volume mydata mounted at /data
Run a Docker container using the busybox image with the volume mydata mounted to the container path /data. Name the container voltest and keep it running interactively.
Docker
Need a hint?

Use docker run with -v mydata:/data to mount the volume and --name voltest to name the container.

3
Create a file hello.txt inside the container with specific content
Inside the running voltest container, create a file named /data/hello.txt containing the text Hello, Docker Volumes!. Use the echo command.
Docker
Need a hint?

Use echo "Hello, Docker Volumes!" > /data/hello.txt to write the text into the file inside the mounted volume.

4
Verify the file exists in the volume by reading it from a new container
Exit the voltest container, then run a new busybox container with the volume mydata mounted at /data. Use the cat /data/hello.txt command to display the file content.
Docker
Need a hint?

Use exit to leave the first container, then run docker run --rm -v mydata:/data busybox cat /data/hello.txt to read the file.