0
0
Dockerdevops~30 mins

Volumes in Compose in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Volumes in Docker Compose
📖 Scenario: You are setting up a simple web application using Docker Compose. You want to keep your application data safe and persistent even if the container stops or is removed. To do this, you will use Docker volumes.
🎯 Goal: Create a Docker Compose file that defines a service with a volume. This volume will store data outside the container so it is not lost when the container is recreated.
📋 What You'll Learn
Create a Docker Compose file named docker-compose.yml
Define a service called webapp using the nginx:latest image
Create a volume named webdata in the Compose file
Mount the volume webdata to the container path /usr/share/nginx/html
Print the content of the Compose file to verify the setup
💡 Why This Matters
🌍 Real World
Docker volumes help keep important data safe even if containers are stopped or deleted. This is useful for databases, web servers, and any app that needs to save files.
💼 Career
Understanding volumes in Docker Compose is essential for DevOps roles to manage persistent data and ensure reliable deployments.
Progress0 / 4 steps
1
Create the basic Docker Compose file
Create a file named docker-compose.yml with a version set to '3.8' and define a service called webapp using the image nginx:latest.
Docker
Need a hint?

Start by specifying the Compose file version and add a service named webapp with the nginx:latest image.

2
Add a volume named webdata
Add a top-level volumes section to the Compose file and define a volume called webdata.
Docker
Need a hint?

Define volumes at the bottom of the file with the name webdata.

3
Mount the volume webdata to the container path
Under the webapp service, add a volumes key that mounts the volume webdata to the container path /usr/share/nginx/html.
Docker
Need a hint?

Use the volumes key inside the webapp service to mount the volume.

4
Print the Docker Compose file content
Write a command to display the content of docker-compose.yml to verify your volume setup.
Docker
Need a hint?

Use cat docker-compose.yml to print the file content.