{"id":825,"date":"2020-07-30T09:28:40","date_gmt":"2020-07-30T09:28:40","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=825"},"modified":"2020-07-30T10:02:46","modified_gmt":"2020-07-30T10:02:46","slug":"storage-drivers","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/07\/30\/storage-drivers\/","title":{"rendered":"Storage Drivers"},"content":{"rendered":"\n<p>The storage driver allows your to create data in the writable layers of the container and it also controls how images and containers are stored and managed on the Docker host. <\/p>\n\n\n\n<p>The files will not be persisted after the container is deleted, and performance wise it is relatively slower than native <code>fs<\/code> performance.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/docs.docker.com\/storage\/storagedriver\/images\/container-layers.jpg\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p>E.g. Let&#8217;s run a image <code>hello-world<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run --name hello hello-world<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello from Docker!\nThis message shows that your installation appears to be working correctly.\n\nTo generate this message, Docker took the following steps:\n 1. The Docker client contacted the Docker daemon.\n 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n    (amd64)\n 3. The Docker daemon created a new container from that image which runs the\n    executable that produces the output you are currently reading.\n 4. The Docker daemon streamed that output to the Docker client, which sent it\n    to your terminal.\n\nTo try something more ambitious, you can run an Ubuntu container with:\n $ docker run -it ubuntu bash\n\nShare images, automate workflows, and more with a free Docker ID:\n https:&#47;&#47;hub.docker.com\/\n\nFor more examples and ideas, visit:\n https:\/\/docs.docker.com\/get-started\/<\/code><\/pre>\n\n\n\n<p>Let&#8217;s inspect the container, and look for <code>GraphDriver<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker container inspect hello<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>        \"GraphDriver\": {\n            \"Data\": {\n                \"LowerDir\": \"\/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff-init\/diff:\/var\/lib\/docker\/overlay2\/39cd21c862ae937b5ac61b392f85dc65c04c7e0cabbf7a15408bf5cc14bd2232\/diff\",\n                \"MergedDir\": \"\/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff\/merged\",\n                \"UpperDir\": \"\/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff\/diff\",\n                \"WorkDir\": \"\/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff\/work\"\n            },\n            \"Name\": \"overlay2\"\n        },<\/code><\/pre>\n\n\n\n<p>You can see the Name of the driver and some locations mentioned in <code>Data<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"WorkDir\": \"\/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff\/work\"<\/code><\/pre>\n\n\n\n<p>If I do a listing in my docker host system I can see this directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -als \/var\/lib\/docker\/overlay2\/228075bcce28b817db0857971a8da5209a5b4743fd2c2a462243bd8d793555ff\/work\ntotal 0\n0 drwx------. 3 root root 18 Jul 30 09:32 .\n0 drwx------. 4 root root 55 Jul 30 09:32 ..\n0 d---------. 2 root root  6 Jul 30 09:32 work<\/code><\/pre>\n\n\n\n<p>How about the <code>image<\/code>?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker image inspect hello-world<\/code><\/pre>\n\n\n\n<p>Look for <code>GraphDriver<\/code> again<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"GraphDriver\": {\n            \"Data\": {\n                \"MergedDir\": \"\/var\/lib\/docker\/overlay2\/39cd21c862ae937b5ac61b392f85dc65c04c7e0cabbf7a15408bf5cc14bd2232\/merged\",\n                \"UpperDir\": \"\/var\/lib\/docker\/overlay2\/39cd21c862ae937b5ac61b392f85dc65c04c7e0cabbf7a15408bf5cc14bd2232\/diff\",\n                \"WorkDir\": \"\/var\/lib\/docker\/overlay2\/39cd21c862ae937b5ac61b392f85dc65c04c7e0cabbf7a15408bf5cc14bd2232\/work\"\n            },\n            \"Name\": \"overlay2\"\n        },<\/code><\/pre>\n\n\n\n<p>A quick directory listing can reveal the contents<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -als \/var\/lib\/docker\/overlay2\/39cd21c862ae937b5ac61b392f85dc65c04c7e0cabbf7a15408bf5cc14bd2232<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>total 12\n0 drwx------.  3 root root   47 Jul 28 08:08 .\n8 drwx------. 50 root root 4096 Jul 30 09:32 ..\n0 -rw-------.  1 root root    0 Jul 30 09:32 committed\n0 drwxr-xr-x.  2 root root   19 Jul 28 08:08 diff\n4 -rw-r--r--.  1 root root   26 Jul 28 08:08 link<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Types of drivers<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>overlay2<\/li><li>aufs<\/li><li>devicemapper<\/li><li>btrfs<\/li><li>vfs<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Read more <a href=\"https:\/\/docs.docker.com\/storage\/storagedriver\/select-storage-driver\/\">here<\/a>.<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li><code>overlay2<\/code> is the preferred storage driver for all currently supported Linux distributions.<\/li><li><code>aufs<\/code> is preferred for the kernels with no support for <code>overlay2<\/code> for Ubuntu 14.01 and older.<\/li><li><code>devicemapper<\/code> requires <code>direct-lvm<\/code> and is recommended storage driver for CentOS7 and earlier and RHEL. (The recent versions do support <code>overlay2<\/code>)<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Linux distribution<\/th><th>Recommended storage drivers<\/th><th>Alternative drivers<\/th><\/tr><\/thead><tbody><tr><td>Docker Engine &#8211; Community on Ubuntu<\/td><td><code>overlay2<\/code> or <code>aufs<\/code> (for Ubuntu 14.04 running on kernel 3.13)<\/td><td><code>overlay<\/code>, <code>devicemapper<\/code>, <code>zfs<\/code>, <code>vfs<\/code><\/td><\/tr><tr><td>Docker Engine &#8211; Community on Debian<\/td><td><code>overlay2<\/code> (Debian Stretch), <code>aufs<\/code> or <code>devicemapper<\/code> (older versions)<\/td><td><code>overlay<\/code>, <code>vfs<\/code><\/td><\/tr><tr><td>Docker Engine &#8211; Community on CentOS<\/td><td><code>overlay2<\/code><\/td><td><code>overlay<\/code>, <code>devicemapper<\/code>, <code>zfs<\/code>, <code>vfs<\/code><\/td><\/tr><tr><td>Docker Engine &#8211; Community on Fedora<\/td><td><code>overlay2<\/code><\/td><td><code>overlay<\/code>, <code>devicemapper<\/code>, <code>zfs<\/code>, <code>vfs<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Supported backing filesystems<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Storage driver<\/th><th>Supported backing filesystems<\/th><\/tr><\/thead><tbody><tr><td><code>overlay2<\/code>, <code>overlay<\/code><\/td><td><code>xfs<\/code> with ftype=1, <code>ext4<\/code><\/td><\/tr><tr><td><code>aufs<\/code><\/td><td><code>xfs<\/code>, <code>ext4<\/code><\/td><\/tr><tr><td><code>devicemapper<\/code><\/td><td><code>direct-lvm<\/code><\/td><\/tr><tr><td><code>btrfs<\/code><\/td><td><code>btrfs<\/code><\/td><\/tr><tr><td><code>zfs<\/code><\/td><td><code>zfs<\/code><\/td><\/tr><tr><td><code>vfs<\/code><\/td><td>any filesystem<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Data persistence is managed using several storage models<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Filesystem storage<ul><li>Used by <code>overlay2<\/code> and <code>aufs<\/code>, and is memory efficient.<\/li><\/ul><\/li><li>Block storage<ul><li><code>devicemapper<\/code> uses it, and is useful for write heavy workloads.<\/li><\/ul><\/li><li>Object storage<ul><li>It is highly flexible and scalable object based store, e.g. A rest API that can push and pull data.<\/li><\/ul><\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Checking the storage driver<\/h3>\n\n\n\n<p>You can use <code>docker info<\/code> to check the driver on your <code>localhost<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Server Version: 19.03.12\n Storage Driver: overlay2\n  Backing Filesystem: xfs\n  Supports d_type: true\n  Native Overlay Diff: true<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/docs.docker.com\/storage\/storagedriver\/select-storage-driver\/#docker-engine&#8212;community<\/li><li>https:\/\/rancher.com\/block-object-file-storage-containers\/<\/li><li>https:\/\/docs.docker.com\/storage\/bind-mounts\/<\/li><li>https:\/\/docs.docker.com\/storage\/volumes\/<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The storage driver allows your to create data in the writable layers of the container and it also controls how images and containers are stored and managed on the Docker host. The files will not be persisted after the container is deleted, and performance wise it is relatively slower than native fs performance. E.g. Let&#8217;s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[86],"tags":[82,88],"class_list":["post-825","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-docker","tag-docker","tag-storage","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=825"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/825\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/828"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}