Switch Storage Driver for Docker on Ubuntu
This blog post is aimed to experiment based on "How to switch to a different storage driver on an existing docker installation in Ubuntu".
Prerequisites
- Ubuntu Linux VM instance on any Cloud or Local VM
- Knowledge about filesystem how it works
Step1: What filesystem provided by your OS
cat /proc/filesystem or grep btrfs /etc/filesystemIs your docker version supports the filesystem available on your VM instance.
grep brtfs /proc/filesystemStep 2: Take a backup of docker folder
cp -au /var/lib/docker /var/lib/docker.bkCreate loop devices attach them using images created by dd command
dd if=/dev/zero of=test1 bs=1 count=1 seek=4294967295 dd if=/dev/zero of=test2 bs=1 count=1 seek=4294969343Here the /dev/zero provides an endless stream of zero bytes when read (if). This function is provided by the kernel and does not require allocating memory. and all writes (of) to given file location. As a result, when you perform the dd, the system generates number of megabytes in zero bytes that simply get discarded.
ls -lhAdding the test1, test2 files as loop devices using losetup command.
losetup -f test1 losetup -f test2Check for the loop devices used:
losetup | grep testCreating pool of BTRFS Filesystem Let us create the Btrfs file-system now for our logical volumes created above.
mkfs.btrfs -f /dev/loop4 /dev/loop5 lsblkNow all set for the Docker storage driver switch So now mount the BTRFS filesystem for /var/lib/docker path.
mkdir -p /var/lib/docker #if already exists ignore this mount -t btrfs /dev/loop4 /var/lib/docker # Validate the device mappings df -h
btrfs filesystem mounting |
cp -au /var/lib/docker.bk/* /var/lib/docker/where you need to create a file called daemon.json if it is not exists. vi /etc/docker/daemon.json that contains by default storage driver 'overlay2'.
{ "storage-driver": "overlay2" }change overlay2 to btrfs driver. After the changes to take effect of the storage driver restart the docker daemon.
# content in the file /etc/docker/daemon.json { "storage-driver": "btrfs" }Start the Docker daemon:
systemctl start docker systemctl status dockerWhen we do this experiment changing the storage driver overlay2 to btrfs driver everything in-accessible. Check images list with overlay2 driver:
docker imagesHere you could see the difference by checking the docker images list with btrfs, where it is new filesystem no image visible here.
Revert back from BTRFS to Overlay2 driver
This part of exeriment will confirms that all the images which you have saved in the overlay2 are accessible back when storage driver shifted from btrfs to 'Overlay2'.cd /var/lib/docker/overlay2; ls -lrtValidate you have storage driver as btrfs `docker info` Stop the docker daemon
systemctl stop dockerChange back to overlay2 in the daemon.json file vi /etc/docker/daemon.json start the docker daemon and check the storage driver:
systemctl start docker; systemctl status docker; docker info #Check the info filter out the 'Storage Driver' value docker info -f 'Storage Driver: {{.Driver}}' #Check the docker images which will show all the previous images. docker images
No comments:
Post a Comment