0
0
Dockerdevops~30 mins

Volumes for persistent data in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Volumes for persistent data
📖 Scenario: You are setting up a Docker container to run a simple web server. You want to make sure that the data created by the server is saved even if the container stops or is removed. This is important because you want to keep your website files safe and not lose them.
🎯 Goal: Learn how to create and use Docker volumes to store persistent data outside the container. You will create a volume, attach it to a container, and verify that data is saved persistently.
📋 What You'll Learn
Create a Docker volume named webdata
Run a Docker container named mywebserver using the nginx image
Mount the webdata volume to the container's /usr/share/nginx/html directory
Verify that the volume is used by checking the container's volume configuration
💡 Why This Matters
🌍 Real World
Docker volumes are used to save data generated by containers so it is not lost when containers stop or are deleted. This is important for databases, web servers, and any service that needs to keep files or data.
💼 Career
Understanding Docker volumes is essential for DevOps roles because managing persistent data in containers is a common task in deploying and maintaining applications.
Progress0 / 4 steps
1
Create a Docker volume
Create a Docker volume called webdata using the docker volume create command.
Docker
Need a hint?

Use the command docker volume create webdata to create the volume.

2
Run a container with the volume attached
Run a Docker container named mywebserver using the nginx image. Attach the webdata volume to the container's /usr/share/nginx/html directory using the --mount option.
Docker
Need a hint?

Use docker run -d --name mywebserver --mount source=webdata,target=/usr/share/nginx/html nginx to start the container.

3
Check the volume usage in the container
Use the docker inspect command on the container mywebserver to check that the volume webdata is mounted at /usr/share/nginx/html.
Docker
Need a hint?

Run docker inspect mywebserver and look for the Mounts section showing webdata mounted at /usr/share/nginx/html.

4
Show the volume mount details from inspect output
Run docker inspect mywebserver and print only the Mounts section to confirm the volume webdata is attached to /usr/share/nginx/html.
Docker
Need a hint?

Use docker inspect mywebserver --format '{{json .Mounts}}' to print the mounts in JSON format.