Part 4 - Docker Storage
Part 4 - Docker Storage
Docker storage
Manage Data
- Data doesn’t persist when container no longer exists
- Difficult to get data out of container
- Container’s writable layer is tightly coupled with the host machine
- Data storage options
- Volumes
- Bind mounts
- Tmpfs (storing file in memory, not persisted)
Docker storage
- Bind mount
- Volume
- Stored at /var/lib/docker/volumes
- tmpfs
Good Use
- Volumes : Sharing data among multiple containers, when container stops or
removed, the volume still exists
- Bind mounts : sharing configuration files from host machine to containers
Case 1
- Create volume name volume1
- Start containers
- Instance1
- Instance2
- Both shares a volume and mounted inside in directory /mydata
- Write number 1 until 1000 to file number.txt in /mydata from instance1
- Check on /mydata on instance2
- Destroy both containers (instance1 and instance 2)
- Run another container (instance3), check whether number.txt is still there
Create volume, and inspect
Volume1 location on
filesystem
Run instance 1
Run instance1 and write number.txt in /mydata
Run instance 2
Run instance1 and write number.txt in /mydata
Start another container
- Remove instance1 and instance2
“docker rm -f instance1 instance2”
- Start instance3
- docker run -it --rm --name instance3 -v volume1:/mydata
alpine:3.18 ls -la /mydata/number.txt
Case 2
- From the previous case we have volume1
- Backup content of volume1 into file backup.zip into local filesystem ( backup )
- Create another volume (volume2)
- Start another container, restore the backup to volume2
- Make local directory for storing backup
C1 C2
C3
mylab3
192.168.20.0/24
192.168.20.254
Cross
subnet
On c3 ???