github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/userguide/storagedriver/aufs-driver.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "AUFS storage driver in practice"
     4  description = "Learn how to optimize your use of AUFS driver."
     5  keywords = ["container, storage, driver, AUFS "]
     6  [menu.main]
     7  parent = "engine_driver"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Docker and AUFS in practice
    12  
    13  AUFS was the first storage driver in use with Docker. As a result, it has a
    14  long and close history with Docker, is very stable, has a lot of real-world
    15  deployments, and has strong community support. AUFS has several features that
    16  make it a good choice for Docker. These features enable:
    17  
    18  - Fast container startup times.
    19  - Efficient use of storage.
    20  - Efficient use of memory.
    21  
    22  Despite its capabilities and long history with Docker, some Linux distributions
    23   do not support AUFS. This is usually because AUFS is not included in the
    24  mainline (upstream) Linux kernel.
    25  
    26  The following sections examine some AUFS features and how they relate to
    27  Docker.
    28  
    29  ## Image layering and sharing with AUFS
    30  
    31  AUFS is a *unification filesystem*. This means that it takes multiple
    32  directories on a single Linux host, stacks them on top of each other, and
    33  provides a single unified view. To achieve this, AUFS uses a *union mount*.
    34  
    35  AUFS stacks multiple directories and exposes them as a unified view through a
    36  single mount point. All of the directories in the stack, as well as the union
    37  mount point, must all exist on the same Linux host. AUFS refers to each
    38  directory that it stacks as a *branch*.
    39  
    40  Within Docker, AUFS union mounts enable image layering. The AUFS storage driver
    41   implements Docker image layers using this union mount system. AUFS branches
    42  correspond to Docker image layers. The diagram below shows a Docker container
    43  based on the `ubuntu:latest` image.
    44  
    45  ![](images/aufs_layers.jpg)
    46  
    47  This diagram shows that each image layer, and the container layer, is
    48  represented in the Docker hosts filesystem as a directory under
    49  `/var/lib/docker/`. The union mount point provides the unified view of all
    50  layers. As of Docker 1.10, image layer IDs do not correspond to the names of
    51  the directories that contain their data.
    52  
    53  AUFS also supports the copy-on-write technology (CoW). Not all storage drivers
    54  do.
    55  
    56  ## Container reads and writes with AUFS
    57  
    58  Docker leverages AUFS CoW technology to enable image sharing and minimize the
    59  use of disk space. AUFS works at the file level. This means that all AUFS CoW
    60  operations copy entire files - even if only a small part of the file is being
    61  modified. This behavior can have a noticeable impact on container performance,
    62   especially if the files being copied are large, below a lot of image layers,
    63  or the CoW operation must search a deep directory tree.
    64  
    65  Consider, for example, an application running in a container needs to add a
    66  single new value to a large key-value store (file). If this is the first time
    67  the file is modified, it does not yet exist in the container's top writable
    68  layer. So, the CoW must *copy up* the file from the underlying image. The AUFS
    69  storage driver searches each image layer for the file. The search order is from
    70   top to bottom. When it is found, the entire file is *copied up* to the
    71  container's top writable layer. From there, it can be opened and modified.
    72  
    73  Larger files obviously take longer to *copy up* than smaller files, and files
    74  that exist in lower image layers take longer to locate than those in higher
    75  layers. However, a *copy up* operation only occurs once per file on any given
    76  container. Subsequent reads and writes happen against the file's copy already
    77  *copied-up* to the container's top layer.
    78  
    79  ## Deleting files with the AUFS storage driver
    80  
    81  The AUFS storage driver deletes a file from a container by placing a *whiteout
    82  file* in the container's top layer. The whiteout file effectively obscures the
    83  existence of the file in the read-only image layers below. The simplified
    84  diagram below shows a container based on an image with three image layers.
    85  
    86  ![](images/aufs_delete.jpg)
    87  
    88  The `file3` was deleted from the container. So, the AUFS storage driver  placed
    89  a whiteout file in the container's top layer. This whiteout file effectively
    90  "deletes" `file3` from the container by obscuring any of the original file's
    91  existence in the image's read-only layers. This works the same no matter which
    92  of the image's read-only layers the file exists in.
    93  
    94  ## Configure Docker with AUFS
    95  
    96  You can only use the AUFS storage driver on Linux systems with AUFS installed.
    97  Use the following command to determine if your system supports AUFS.
    98  
    99      $ grep aufs /proc/filesystems
   100  
   101      nodev   aufs
   102  
   103  This output indicates the system supports AUFS. Once you've verified your
   104  system supports AUFS, you can must instruct the Docker daemon to use it. You do
   105  this from the command line with the `dockerd` command:
   106  
   107      $ sudo dockerd --storage-driver=aufs &
   108  
   109  
   110  Alternatively, you can edit the Docker config file and add the
   111  `--storage-driver=aufs` option to the `DOCKER_OPTS` line.
   112  
   113      # Use DOCKER_OPTS to modify the daemon startup options.
   114      DOCKER_OPTS="--storage-driver=aufs"
   115  
   116  Once your daemon is running, verify the storage driver with the `docker info`
   117  command.
   118  
   119      $ sudo docker info
   120  
   121      Containers: 1
   122      Images: 4
   123      Storage Driver: aufs
   124       Root Dir: /var/lib/docker/aufs
   125       Backing Filesystem: extfs
   126       Dirs: 6
   127       Dirperm1 Supported: false
   128      Execution Driver: native-0.2
   129      ...output truncated...
   130  
   131  The output above shows that the Docker daemon is running the AUFS storage
   132  driver on top of an existing `ext4` backing filesystem.
   133  
   134  ## Local storage and AUFS
   135  
   136  As the `dockerd` runs with the AUFS driver, the driver stores images and
   137  containers within the Docker host's local storage area under
   138  `/var/lib/docker/aufs/`.
   139  
   140  ### Images
   141  
   142  Image layers and their contents are stored under
   143  `/var/lib/docker/aufs/diff/`. With Docker 1.10 and higher, image layer IDs do
   144  not correspond to directory names.
   145  
   146  The `/var/lib/docker/aufs/layers/` directory contains metadata about how image
   147  layers are stacked. This directory contains one file for every image or
   148  container layer on the Docker host (though file names no longer match image
   149  layer IDs). Inside each file are the names of the directories that exist below
   150  it in the stack
   151  
   152  The command below shows the contents of a metadata file in
   153  `/var/lib/docker/aufs/layers/` that lists the three directories that are
   154  stacked below it in the union mount. Remember, these directory names do no map
   155  to image layer IDs with Docker 1.10 and higher.
   156  
   157      $ cat /var/lib/docker/aufs/layers/91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c
   158  
   159      d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82
   160      c22013c8472965aa5b62559f2b540cd440716ef149756e7b958a1b2aba421e87
   161      d3a1f33e8a5a513092f01bb7eb1c2abf4d711e5105390a3fe1ae2248cfde1391
   162  
   163  The base layer in an image has no image layers below it, so its file is empty.
   164  
   165  ### Containers
   166  
   167  Running containers are mounted below `/var/lib/docker/aufs/mnt/<container-id>`.
   168   This is where the AUFS union mount point that exposes the container and all
   169  underlying image layers as a single unified view exists. If a container is not
   170  running, it still has a directory here but it is empty. This is because AUFS
   171  only mounts a container when it is running. With Docker 1.10 and higher,
   172   container IDs no longer correspond to directory names under
   173  `/var/lib/docker/aufs/mnt/<container-id>`.
   174  
   175  Container metadata and various config files that are placed into the running
   176  container are stored in `/var/lib/docker/containers/<container-id>`. Files in
   177  this directory exist for all containers on the system, including ones that are
   178  stopped. However, when a container is running the container's log files are
   179  also in this directory.
   180  
   181  A container's thin writable layer is stored in a directory under
   182  `/var/lib/docker/aufs/diff/`. With Docker 1.10 and higher, container IDs no
   183  longer correspond to directory names. However, the containers thin writable
   184  layer still exists under here and is stacked by AUFS as the top writable layer
   185  and is where all changes to the container are stored. The directory exists even
   186   if the container is stopped. This means that restarting a container will not
   187  lose changes made to it. Once a container is deleted, it's thin writable layer
   188  in this directory is deleted.
   189  
   190  ## AUFS and Docker performance
   191  
   192  To summarize some of the performance related aspects already mentioned:
   193  
   194  - The AUFS storage driver is a good choice for PaaS and other similar use-cases
   195   where container density is important. This is because AUFS efficiently shares
   196  images between multiple running containers, enabling fast container start times
   197   and minimal use of disk space.
   198  
   199  - The underlying mechanics of how AUFS shares files between image layers and
   200  containers uses the systems page cache very efficiently.
   201  
   202  - The AUFS storage driver can introduce significant latencies into container
   203  write performance. This is because the first time a container writes to any
   204  file, the file has be located and copied into the containers top writable
   205  layer. These latencies increase and are compounded when these files exist below
   206   many image layers and the files themselves are large.
   207  
   208  One final point. Data volumes provide the best and most predictable
   209  performance. This is because they bypass the storage driver and do not incur 
   210  any of the potential overheads introduced by thin provisioning and
   211  copy-on-write. For this reason, you may want to place heavy write workloads on
   212  data volumes.
   213  
   214  ## Related information
   215  
   216  * [Understand images, containers, and storage drivers](imagesandcontainers.md)
   217  * [Select a storage driver](selectadriver.md)
   218  * [Btrfs storage driver in practice](btrfs-driver.md)
   219  * [Device Mapper storage driver in practice](device-mapper-driver.md)