Pages

Friday, July 20, 2018

Union File System for Containers

As we all know that container are run from image which are layers. The Implementation is based on Union file systems. UnionFS is a file systems that operate by creating layers making them very lightweight and fast. There are multiple implementations of UnionFS like AUFS, btrfs , vfs and device mapper.

Basically union mounting is a way of combining multiple directories into one that appears to contain their combined contents. So a UnionFS takes a existing file system and overlays it on a newer file system. It allows files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system. Contents of directories which have the same path within the merged branches will be seen together in a single merged directory, within the new virtual filesystem.

Lets see a implementation of union Fs.  
1.   Install aufs-tools on a Ubnutu machine.
2.   Create a dir in home location : mkdir /home/home_dir.
3.   Create a dir in tmp location : mkdir /tmp/tmp_dir
4.   Mount both dir using the aufs as, mount -t aufs -o br=/tmp/tmp_dir:/home/home_dir none /tmp/aufs-root/
We have mounted the /tmp/tmp_dir and /home/home_dir onto a single file system /tmp/aufs-root
Now once we create file in /tmp/home_dir and /home/home_dir directories and check in the /tmp/aufs-root we can see,
          root@work-node2:/tmp/aufs-root# ll
-rw-r--r-- 1 root root    0 Jul 17 01:38 home_dir_file
-rw-r--r-- 1 root root    0 Jul 17 01:38 tmp_dir_file

So we have basically mounted the 2 directories as layers on /tmp/aufs-root. Changes made to these files will also be reflected on the originals. This is basis for docker container technology.

No comments :

Post a Comment