Home Explore Blog Models CI



docker

2nd chunk of `content/manuals/engine/storage/drivers/zfs-driver.md`
5527cc81f4ba37511b72adff62de7d24954ac29d159e9c4e0000000100000e8c
    like this:

    ```json
    {
      "storage-driver": "zfs"
    }
    ```

    Save and close the file.

5.  Start Docker. Use `docker info` to verify that the storage driver is `zfs`.

    ```console
    $ sudo docker info
      Containers: 0
       Running: 0
       Paused: 0
       Stopped: 0
      Images: 0
      Server Version: 17.03.1-ce
      Storage Driver: zfs
       Zpool: zpool-docker
       Zpool Health: ONLINE
       Parent Dataset: zpool-docker
       Space Used By Parent: 249856
       Space Available: 103498395648
       Parent Quota: no
       Compression: off
    <...>
    ```

## Manage `zfs`

### Increase capacity on a running device

To increase the size of the `zpool`, you need to add a dedicated block device to
the Docker host, and then add it to the `zpool` using the `zpool add` command:

```console
$ sudo zpool add zpool-docker /dev/xvdh
```

### Limit a container's writable storage quota

If you want to implement a quota on a per-image/dataset basis, you can set the
`size` storage option to limit the amount of space a single container can use
for its writable layer.

Edit `/etc/docker/daemon.json` and add the following:

```json
{
  "storage-driver": "zfs",
  "storage-opts": ["size=256M"]
}
```

See all storage options for each storage driver in the
[daemon reference documentation](/reference/cli/dockerd/#daemon-storage-driver)

Save and close the file, and restart Docker.

## How the `zfs` storage driver works

ZFS uses the following objects:

- **filesystems**: thinly provisioned, with space allocated from the `zpool` on
  demand.
- **snapshots**: read-only space-efficient point-in-time copies of filesystems.
- **clones**: Read-write copies of snapshots. Used for storing the differences
  from the previous layer.

The process of creating a clone:

![ZFS snapshots and clones](/Users/baehyunsol/Documents/Rust/ragit/sample/docker/content/manuals/engine/storage/drivers/images/zfs_clones.webp?w=450)


1.  A read-only snapshot is created from the filesystem.
2.  A writable clone is created from the snapshot. This contains any differences
    from the parent layer.

Filesystems, snapshots, and clones all allocate space from the underlying
`zpool`.

### Image and container layers on-disk

Each running container's unified filesystem is mounted on a mount point in
`/var/lib/docker/zfs/graph/`. Continue reading for an explanation of how the
unified filesystem is composed.

### Image layering and sharing

The base layer of an image is a ZFS filesystem. Each child layer is a ZFS clone
based on a ZFS snapshot of the layer below it. A container is a ZFS clone based
on a ZFS Snapshot of the top layer of the image it's created from.

The diagram below shows how this is put together with a running container based
on a two-layer image.

![ZFS pool for Docker container](/Users/baehyunsol/Documents/Rust/ragit/sample/docker/content/manuals/engine/storage/drivers/images/zfs_zpool.webp?w=600)

When you start a container, the following steps happen in order:

1.  The base layer of the image exists on the Docker host as a ZFS filesystem.

2.  Additional image layers are clones of the dataset hosting the image layer
    directly below it.

    In the diagram, "Layer 1" is added by taking a ZFS snapshot of the base
    layer and then creating a clone from that snapshot. The clone is writable and
    consumes space on-demand from the zpool. The snapshot is read-only,
    maintaining the base layer as an immutable object.

3.  When the container is launched, a writable layer is added above the image.

    In the diagram, the container's read-write layer is created by making
    a snapshot of the top layer of the image (Layer 1) and creating a clone from

Title: Managing ZFS and How it Works
Summary
This section details how to manage ZFS in Docker, including increasing the capacity of a Zpool by adding devices and limiting a container's writable storage quota using the `size` storage option in `/etc/docker/daemon.json`. It also explains the inner workings of the ZFS storage driver, including the use of filesystems, snapshots, and clones. Finally, it provides an in-depth explanation of how image and container layers are stored on disk, demonstrating how ZFS clones and snapshots are used for layering and sharing, including the steps that occur when a container is started.