Docker supports many storage drivers like below, but if you work on ubuntu use AUFS if linux kernel version is less than 4.0 otherwise use overlay(overlay2) as it has better performance.
Note: AUFS is not accepted by linux kernel(not in main) but it's initially default storage driver for docker for ubuntu/debian.
how docker uses AUFS
Aufs merges different dirs into single one, basic usage, refer to Aufs-basic, here let’s say how aufs works for docker.
Actually, Aufs($ mount -t aufs xx) only happens when you create a container(event it's not started), at that time docker creates a RW layer(called container layer), then mounts different layers[container layer + image layers] into single dir, when you start this container, chroot to this single dir as the root dir for it, that's it.
Note: this mount point(single dir) and RW layer are deleted only when the container is removed.
/var/lib/docker changes when created container
let's take a real example on ubuntu to see how it works, in order to understand it correctly, it's better read how image stored on ubuntu firstly.
Initially, we only have one image, ubuntu:latest which has four layers that’s where we begin.
1 2 3 4 5 6
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 2ca708c1c9cc 3 weeks ago 64.19 MB
Before created $ ls -l /var/lib/docker/aufs/diff total 16 drwxr-xr-x 6 root root 4096 Oct 14 09:50 268f3ca66142b2b9791504df67c604a5f0bf331064f4e1f899fcdd33686b602d drwxr-xr-x 21 root root 4096 Oct 14 09:50 38fd587650e8a0befc2a177395a2afa380abcd32ac78316c6a38ea6b01bdadd7 drwxr-xr-x 3 root root 4096 Oct 14 09:50 39d5b8fbe7446545c8e982bc3c2e0a0e955a81c99a88a85121252800406c88cf drwxr-xr-x 3 root root 4096 Oct 14 09:50 9bd9ca976269998def585a7848e180207f88cdec9e95b11e930532cfe84780e6
After created $ ls -l /var/lib/docker/aufs/diff total 24 drwxr-xr-x 4 root root 4096 Oct 14 10:15 0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47 drwxr-xr-x 6 root root 4096 Oct 14 10:15 0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47-init # above are two new added layers(RW layer + init Layer) for this container # RW layer is empty # init layer is system related, some system required info aufs/diff/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47-init/ |-- dev | |-- console | |-- pts | `-- shm `-- etc |-- hostname |-- hosts |-- mtab -> /proc/mounts `-- resolv.conf
drwxr-xr-x 6 root root 4096 Oct 14 09:50 268f3ca66142b2b9791504df67c604a5f0bf331064f4e1f899fcdd33686b602d drwxr-xr-x 21 root root 4096 Oct 14 09:50 38fd587650e8a0befc2a177395a2afa380abcd32ac78316c6a38ea6b01bdadd7 drwxr-xr-x 3 root root 4096 Oct 14 09:50 39d5b8fbe7446545c8e982bc3c2e0a0e955a81c99a88a85121252800406c88cf drwxr-xr-x 3 root root 4096 Oct 14 09:50 9bd9ca976269998def585a7848e180207f88cdec9e95b11e930532cfe84780e6
# Before created $ ls -l /var/lib/docker/aufs/mnt/ total 16 drwxr-xr-x 2 root root 4096 Oct 14 09:50 268f3ca66142b2b9791504df67c604a5f0bf331064f4e1f899fcdd33686b602d drwxr-xr-x 2 root root 4096 Oct 14 09:50 38fd587650e8a0befc2a177395a2afa380abcd32ac78316c6a38ea6b01bdadd7 drwxr-xr-x 2 root root 4096 Oct 14 09:50 39d5b8fbe7446545c8e982bc3c2e0a0e955a81c99a88a85121252800406c88cf drwxr-xr-x 2 root root 4096 Oct 14 09:50 9bd9ca976269998def585a7848e180207f88cdec9e95b11e930532cfe84780e6
# After created $ ls -l /var/lib/docker/aufs/mnt/ total 24 drwxr-xr-x 2 root root 4096 Oct 14 10:15 0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47 drwxr-xr-x 2 root root 4096 Oct 14 10:15 0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47-init
# Above is mount point for RW layer and init layer, it's only mounted when docker runs here just create # an empty directory!!!!
drwxr-xr-x 2 root root 4096 Oct 14 09:50 268f3ca66142b2b9791504df67c604a5f0bf331064f4e1f899fcdd33686b602d drwxr-xr-x 2 root root 4096 Oct 14 09:50 38fd587650e8a0befc2a177395a2afa380abcd32ac78316c6a38ea6b01bdadd7 drwxr-xr-x 2 root root 4096 Oct 14 09:50 39d5b8fbe7446545c8e982bc3c2e0a0e955a81c99a88a85121252800406c88cf drwxr-xr-x 2 root root 4096 Oct 14 09:50 9bd9ca976269998def585a7848e180207f88cdec9e95b11e930532cfe84780e6
$ mount -t aufs -o br=aufs/diff/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47:aufs/diff/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47-init xxx none aufs/mnt/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47 # mount happens only container runs!!!! # Before container run root@dev:/var/lib/docker# tree aufs/mnt/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47/ aufs/mnt/0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47/ 0 directories, 0 files
# After container runs
containers/ change
1 2 3 4 5 6 7 8 9
# Before created root@dev:/var/lib/docker# ls -l containers/ total 0
# After created root@dev:/var/lib/docker# ls -l containers/ total 4 drwx------ 2 root root 4096 Oct 14 10:15 ba2377cb603f8c5ef44619af1bb8734a870139939913777896438e34facd3a3e # it stores conf and runtime info for this container
image/aufs/layerdb/mounts change
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Before created root@dev:/var/lib/docker# ls -l image/aufs/layerdb/mounts/ total 0
# After created
root@dev:/var/lib/docker# ls -l image/aufs/layerdb/mounts/ total 4 drwxr-xr-x 2 root root 4096 Oct 14 10:15 ba2377cb603f8c5ef44619af1bb8734a870139939913777896438e34facd3a3e
root@dev:/var/lib/docker# tree image/aufs/layerdb/mounts/ba2377cb603f8c5ef44619af1bb8734a870139939913777896438e34facd3a3e/ image/aufs/layerdb/mounts/ba2377cb603f8c5ef44619af1bb8734a870139939913777896438e34facd3a3e/ |-- init-id |-- mount-id `-- parent
root@dev:/var/lib/docker# cat image/aufs/layerdb/mounts/ba2377cb603f8c5ef44619af1bb8734a870139939913777896438e34facd3a3e/mount-id 0d6eb9abafaca00679acf48400264dbb2704a996ae2781a615809ec672859a47 # it stores the mount point(mount-id) for this container
That's almost the changes from storage view when you create a container.