diff driver主要用于得到layer和parent layer的diff 文件,overlayfs内核本身支持这种行为(只要获取layer的目录就可以),这属于native diff。

    如果开启了OVERLAY_FS_REDIRECT_DIR内核选项,就不能使用overlay native diff driver。

    1. config OVERLAY_FS_REDIRECT_DIR
    2. bool "Overlayfs: turn on redirect dir feature by default"
    3. depends on OVERLAY_FS
    4. help
    5. If this config option is enabled then overlay filesystems will use redirects when renaming directories by default. In this case it is still possible to turn off redirects globally with the "redirect_dir=off" module option or on a filesystem instance basis with the "redirect_dir=off" mount option.
    6. Note, that redirects are not backward compatible. That is, mounting an overlay which has redirects on a kernel that doesn't support this feature will have unexpected results.
    7. If unsure, say N.

    the directory rename was implemented as a redirect using an extended file attribute (xattr) 。

    Some discussion on moby issues 34342 and 34320 indicates that, if all of the following are true:

    1. the OVERLAY_FS_REDIRECT_DIR kernel option is enabled
    2. the storage engine is overlay2 (the default in most cases)
    3. docker is storing images on a file system that is not mounted with redirect_dir=off
    4. the “native” diff driver is used
    5. a nonempty directory is renamed as part of a docker build, e.g. in a Dockerfile like the following:
      1. FROM busybox
      2. RUN mkdir /dir1
      3. RUN touch /dir1/newfile
      4. RUN mv /dir1 /dir2
      Then the resulting image will not properly record the contents of the renamed directory (i.e., dir2 will not contain newfile) because the directory rename was implemented as a redirect using an extended file attribute (xattr) which is not understood by the docker archiving process. To solve this problem, when the first three conditions above are met, then docker will use the “naive” diff driver which produces correct images, but is slower than the “native” diff driver.