Docker Assignment– 3

Docker Volumes & Data Persistence

Basic Questions

  1. Run an alpine container, create a file inside it, stop the container, and check if the file still exists after restart.
  2. Write a note explaining why containers are ephemeral in nature.
  3. Create a Docker volume named myvolume.
  4. List all volumes on your system.
  5. Inspect the myvolume and note its mount path.
  6. Remove a specific volume using docker volume rm.
  7. Remove all unused volumes using docker volume prune.
  8. Run an nginx container and attach it to myvolume at /usr/share/nginx/html.
  9. Create a bind mount from your host folder ./html to container path /usr/share/nginx/html.
  10. Compare bind mounts and volumes by creating both and noting the differences.
  11. Create a container with a volume mounted at /data and write a file to it.
  12. Run another container using the same volume and verify the file is shared.
  13. Create a MySQL container with a volume mounted at /var/lib/mysql.
  14. Stop and restart the MySQL container and check if data is preserved.
  15. Create multiple containers sharing the same volume and confirm data is accessible across them.
  16. Create and remove a named volume in a single command.
  17. Create a container with multiple volumes mounted at different paths.
  18. Inspect the mount details of a container using docker inspect.
  19. Display disk usage of volumes using docker system df –volumes.
  20. Write a short summary of when to use volumes vs bind mounts.

Intermediate Questions

  1. Run two nginx containers sharing a single volume and update content from one container.
  2. Create a host directory ./data and use a bind mount to persist container data.
  3. Run a mysql container with root password set and persist data in a named volume.
  4. Insert data into MySQL, stop the container, remove it, start a new one with the same volume, and verify data exists.
  5. Backup a Docker volume by running a temporary container with tar.
  6. Restore a volume backup into a new volume and mount it to a container.
  7. Create three volumes and attach them to a single container.
  8. Create a bind mount and change file content on the host; verify changes inside the container.
  9. Create a bind mount and change file content inside the container; verify changes on the host.
  10. Create a volume and attach it read-only to a container; try writing inside it.
  11. Run a container with a volume and use docker exec to explore its content.
  12. Create a temporary volume using –mount type=tmpfs and check its behavior.
  13. Run a container with two bind mounts from different host directories.
  14. Create a container with both a volume and a bind mount at different paths.
  15. Run docker volume ls -q to list only volume names.
  16. Run a container, remove it, and check if the associated volume still exists.
  17. Create a script to back up all volumes into a compressed archive.
  18. Restore volumes from a compressed archive into a fresh Docker installation.
  19. Run docker system prune –volumes and check space usage before and after.
  20. Write a Playbook (steps) for persisting MySQL data using volumes.

Advanced Questions

  1. Create a complete workflow: Start MySQL with a volume, insert data, remove the container, start a new one with the same volume, and verify persistence.
  2. Create two MySQL containers sharing the same volume and check if they access the same data.
  3. Backup MySQL data stored in a volume using docker run –rm with tar.
  4. Restore the MySQL volume backup into a new MySQL container.
  5. Create a multi-container setup where nginx serves content from a shared volume updated by another container.
  6. Demonstrate data persistence by upgrading a MySQL container to a new version without data loss.
  7. Run a container with a bind mount pointing to a Git repo and verify auto-sync of code.
  8. Use a named volume in a Docker Compose file to persist MySQL data.
  9. Automate volume backup using a shell script scheduled via cron.
  10. Document and demonstrate the full workflow: Create volume → Start MySQL → Insert Data → Backup Volume → Restore → Verify Data.