Docker Assignment– 3
Docker Volumes & Data Persistence
Basic Questions
- Run an alpine container, create a file inside it, stop the container, and check if the file still exists after restart.
- Write a note explaining why containers are ephemeral in nature.
- Create a Docker volume named myvolume.
- List all volumes on your system.
- Inspect the myvolume and note its mount path.
- Remove a specific volume using docker volume rm.
- Remove all unused volumes using docker volume prune.
- Run an nginx container and attach it to myvolume at /usr/share/nginx/html.
- Create a bind mount from your host folder ./html to container path /usr/share/nginx/html.
- Compare bind mounts and volumes by creating both and noting the differences.
- Create a container with a volume mounted at /data and write a file to it.
- Run another container using the same volume and verify the file is shared.
- Create a MySQL container with a volume mounted at /var/lib/mysql.
- Stop and restart the MySQL container and check if data is preserved.
- Create multiple containers sharing the same volume and confirm data is accessible across them.
- Create and remove a named volume in a single command.
- Create a container with multiple volumes mounted at different paths.
- Inspect the mount details of a container using docker inspect.
- Display disk usage of volumes using docker system df –volumes.
- Write a short summary of when to use volumes vs bind mounts.
Intermediate Questions
- Run two nginx containers sharing a single volume and update content from one container.
- Create a host directory ./data and use a bind mount to persist container data.
- Run a mysql container with root password set and persist data in a named volume.
- Insert data into MySQL, stop the container, remove it, start a new one with the same volume, and verify data exists.
- Backup a Docker volume by running a temporary container with tar.
- Restore a volume backup into a new volume and mount it to a container.
- Create three volumes and attach them to a single container.
- Create a bind mount and change file content on the host; verify changes inside the container.
- Create a bind mount and change file content inside the container; verify changes on the host.
- Create a volume and attach it read-only to a container; try writing inside it.
- Run a container with a volume and use docker exec to explore its content.
- Create a temporary volume using –mount type=tmpfs and check its behavior.
- Run a container with two bind mounts from different host directories.
- Create a container with both a volume and a bind mount at different paths.
- Run docker volume ls -q to list only volume names.
- Run a container, remove it, and check if the associated volume still exists.
- Create a script to back up all volumes into a compressed archive.
- Restore volumes from a compressed archive into a fresh Docker installation.
- Run docker system prune –volumes and check space usage before and after.
- Write a Playbook (steps) for persisting MySQL data using volumes.
Advanced Questions
- 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.
- Create two MySQL containers sharing the same volume and check if they access the same data.
- Backup MySQL data stored in a volume using docker run –rm with tar.
- Restore the MySQL volume backup into a new MySQL container.
- Create a multi-container setup where nginx serves content from a shared volume updated by another container.
- Demonstrate data persistence by upgrading a MySQL container to a new version without data loss.
- Run a container with a bind mount pointing to a Git repo and verify auto-sync of code.
- Use a named volume in a Docker Compose file to persist MySQL data.
- Automate volume backup using a shell script scheduled via cron.
- Document and demonstrate the full workflow: Create volume → Start MySQL → Insert Data → Backup Volume → Restore → Verify Data.