2014-03-27 12:48:32 -04:00
## devicemapper - a storage backend based on Device Mapper
### Theory of operation
The device mapper graphdriver uses the device mapper thin provisioning
module (dm-thinp) to implement CoW snapshots. For each devicemapper
2014-06-05 18:13:43 -04:00
graph location (typically `/var/lib/docker/devicemapper` , $graph below)
2014-03-27 12:48:32 -04:00
a thin pool is created based on two block devices, one for data and
one for metadata. By default these block devices are created
2014-08-05 21:11:32 -04:00
automatically by using loopback mounts of automatically created sparse
2014-03-27 12:48:32 -04:00
files.
The default loopback files used are `$graph/devicemapper/data` and
`$graph/devicemapper/metadata` . Additional metadata required to map
from docker entities to the corresponding devicemapper volumes is
stored in the `$graph/devicemapper/json` file (encoded as Json).
2014-08-05 21:11:32 -04:00
In order to support multiple devicemapper graphs on a system, the thin
2014-03-27 12:48:32 -04:00
pool will be named something like: `docker-0:33-19478248-pool` , where
2014-06-24 02:27:24 -04:00
the `0:33` part is the minor/major device nr and `19478248` is the
2014-03-27 12:48:32 -04:00
inode number of the $graph directory.
2014-08-05 21:11:32 -04:00
On the thin pool, docker automatically creates a base thin device,
2014-03-27 12:48:32 -04:00
called something like `docker-0:33-19478248-base` of a fixed
2014-08-05 21:11:32 -04:00
size. This is automatically formatted with an empty filesystem on
creation. This device is the base of all docker images and
2014-03-27 12:48:32 -04:00
containers. All base images are snapshots of this device and those
images are then in turn used as snapshots for other images and
eventually containers.
2015-01-19 17:37:08 -05:00
### Information on `docker info`
As of docker-1.4.1, `docker info` when using the `devicemapper` storage driver
will display something like:
$ sudo docker info
[...]
Storage Driver: devicemapper
Pool Name: docker-253:1-17538953-pool
Pool Blocksize: 65.54 kB
Data file: /dev/loop4
Metadata file: /dev/loop4
Data Space Used: 2.536 GB
Data Space Total: 107.4 GB
2015-01-31 01:21:34 -05:00
Data Space Available: 104.8 GB
2015-01-19 17:37:08 -05:00
Metadata Space Used: 7.93 MB
Metadata Space Total: 2.147 GB
2015-01-31 01:21:34 -05:00
Metadata Space Available: 2.14 GB
2015-01-19 17:37:08 -05:00
Udev Sync Supported: true
Data loop file: /home/docker/devicemapper/devicemapper/data
Metadata loop file: /home/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.82-git (2013-10-04)
[...]
#### status items
Each item in the indented section under `Storage Driver: devicemapper` are
status information about the driver.
* `Pool Name` name of the devicemapper pool for this driver.
* `Pool Blocksize` tells the blocksize the thin pool was initialized with. This only changes on creation.
* `Data file` blockdevice file used for the devicemapper data
* `Metadata file` blockdevice file used for the devicemapper metadata
* `Data Space Used` tells how much of `Data file` is currently used
* `Data Space Total` tells max size the `Data file`
2015-02-09 17:51:48 -05:00
* `Data Space Available` tells how much free space there is in the `Data file` . If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem.
2015-01-19 17:37:08 -05:00
* `Metadata Space Used` tells how much of `Metadata file` is currently used
* `Metadata Space Total` tells max size the `Metadata file`
2015-02-09 17:51:48 -05:00
* `Metadata Space Available` tells how much free space there is in the `Metadata file` . If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem.
2015-01-19 17:37:08 -05:00
* `Udev Sync Supported` tells whether devicemapper is able to sync with Udev. Should be `true` .
* `Data loop file` file attached to `Data file` , if loopback device is used
* `Metadata loop file` file attached to `Metadata file` , if loopback device is used
* `Library Version` from the libdevmapper used
2014-03-27 12:48:32 -04:00
### options
The devicemapper backend supports some options that you can specify
2014-08-05 21:11:32 -04:00
when starting the docker daemon using the `--storage-opt` flags.
2014-07-10 00:14:06 -04:00
This uses the `dm` prefix and would be used something like `docker -d --storage-opt dm.foo=bar` .
2014-03-27 12:48:32 -04:00
Here is the list of supported options:
* `dm.basesize`
Specifies the size to use when creating the base device, which
limits the size of images and containers. The default value is
10G. Note, thin devices are inherently "sparse", so a 10G device
which is mostly empty doesn't use 10 GB of space on the
pool. However, the filesystem will use more space for the empty
2014-08-05 22:28:07 -04:00
case the larger the device is. **Warning** : This value affects the
system-wide "base" empty filesystem that may already be
initialized and inherited by pulled images. Typically, a change
to this value will require additional steps to take effect: 1)
stop `docker -d` , 2) `rm -rf /var/lib/docker` , 3) start `docker -d` .
2014-03-27 12:48:32 -04:00
Example use:
``docker -d --storage-opt dm.basesize=20G``
* `dm.loopdatasize`
Specifies the size to use when creating the loopback file for the
"data" device which is used for the thin pool. The default size is
100G. Note that the file is sparse, so it will not initially take
up this much space.
Example use:
``docker -d --storage-opt dm.loopdatasize=200G``
* `dm.loopmetadatasize`
Specifies the size to use when creating the loopback file for the
"metadadata" device which is used for the thin pool. The default size is
2G. Note that the file is sparse, so it will not initially take
up this much space.
Example use:
``docker -d --storage-opt dm.loopmetadatasize=4G``
2014-03-18 09:23:43 -04:00
* `dm.fs`
Specifies the filesystem type to use for the base device. The supported
options are "ext4" and "xfs". The default is "ext4"
Example use:
``docker -d --storage-opt dm.fs=xfs``
* `dm.mkfsarg`
Specifies extra mkfs arguments to be used when creating the base device.
Example use:
``docker -d --storage-opt "dm.mkfsarg=-O ^has_journal"``
* `dm.mountopt`
Specifies extra mount options used when mounting the thin devices.
Example use:
``docker -d --storage-opt dm.mountopt=nodiscard``
2014-03-28 10:36:55 -04:00
2014-10-24 19:25:24 -04:00
* `dm.thinpooldev`
Specifies a custom blockdevice to use for the thin pool.
If using a block device for device mapper storage, ideally lvm2
would be used to create/manage the thin-pool volume that is then
handed to docker to exclusively create/manage the thin and thin
snapshot volumes needed for it's containers. Managing the thin-pool
outside of docker makes for the most feature-rich method of having
docker utilize device mapper thin provisioning as the backing
storage for docker's containers. lvm2-based thin-pool management
feature highlights include: automatic or interactive thin-pool
resize support, dynamically change thin-pool features, automatic
thinp metadata checking when lvm2 activates the thin-pool, etc.
Example use:
``docker -d --storage-opt dm.thinpooldev=/dev/mapper/thin-pool``
2014-03-28 10:36:55 -04:00
* `dm.datadev`
Specifies a custom blockdevice to use for data for the thin pool.
If using a block device for device mapper storage, ideally both
datadev and metadatadev should be specified to completely avoid
using the loopback device.
Example use:
``docker -d --storage-opt dm.datadev=/dev/sdb1 --storage-opt dm.metadatadev=/dev/sdc1``
* `dm.metadatadev`
Specifies a custom blockdevice to use for metadata for the thin
pool.
For best performance the metadata should be on a different spindle
than the data, or even better on an SSD.
If setting up a new metadata pool it is required to be valid. This
can be achieved by zeroing the first 4k to indicate empty
metadata, like this:
``dd if=/dev/zero of=$metadata_dev bs=4096 count=1```
Example use:
``docker -d --storage-opt dm.datadev=/dev/sdb1 --storage-opt dm.metadatadev=/dev/sdc1``
2014-04-01 09:41:25 -04:00
2014-06-20 11:53:18 -04:00
* `dm.blocksize`
2014-06-26 12:06:41 -04:00
Specifies a custom blocksize to use for the thin pool. The default
2014-07-09 16:20:01 -04:00
blocksize is 64K.
2014-06-20 11:53:18 -04:00
Example use:
2014-07-09 16:20:01 -04:00
``docker -d --storage-opt dm.blocksize=512K``
2014-06-20 11:53:18 -04:00
2014-04-01 09:41:25 -04:00
* `dm.blkdiscard`
Enables or disables the use of blkdiscard when removing
devicemapper devices. This is enabled by default (only) if using
2015-02-04 19:57:33 -05:00
loopback devices and is required to resparsify the loopback file
2014-04-01 09:41:25 -04:00
on image/container removal.
Disabling this on loopback can lead to *much* faster container
removal times, but will make the space used in /var/lib/docker
directory not be returned to the system for other use when
containers are removed.
Example use:
``docker -d --storage-opt dm.blkdiscard=false``