Docker卷插件

作者: 印随2018 | 来源:发表于2019-06-28 13:22 被阅读16次

    volume plugin

    Docker插件机制简介

    Docker公司对Docker的扩展分成三个级别,从低到高分别是:User-facing API,该API是Docker提供用于串联出一些场景的API;第二层是插件(Plugins),也是今天的主要介绍内容,Plugins和Docker是两个相互独立的进程,它们之间通过一些预定的通讯协议进行功能扩展;第三层是叫Drivers,是Docker实现功能的一些驱动,例如一些文件存储的驱动。目前,大多数Drivers都是官方出的,当有特定需求或者是用到独特技术时,开发者可以自己写相应的驱动。

    卷插件工作原理

    从下图可以看出,卷插件是一个独立运行的进程


    image.png

    卷插件需要提供两种REST API:

    • Voluem-Plugin REST API
      用于docker和插件通信
    • CLI REST API
      命令行工具管理插件

    已有的卷插件

    • Convoy:
      一种基于本地存储的单机版插件,支持的驱动有Device Mapper、VFS、EBS等
    • Flocker:
      另外一个功能很强大的卷插件,支持多种后台存储驱动,包括OpenStack Cinder,AWS EBS,EMC ScaleIO、ZFS等。

    Convoy 试用

    # 下载安装插件
    wget https://github.com/rancher/convoy/releases/download/v0.5.2/convoy.tar.gz
    tar xvzf convoy.tar.gz
    sudo cp convoy/convoy convoy/convoy-pdata_tools /usr/local/bin/
    sudo mkdir -p /etc/docker/plugins/
    sudo bash -c 'echo "unix:///var/run/convoy/convoy.sock" > /etc/docker/plugins/convoy.spec'
    
    # 启动插件进程
    convoy daemon --drivers vfs --driver-opts path=/data
    
    # 创建卷
    convoy create volume_data
    
    # docker 使用
    docker run -itd -v volume_data:/volume_data --volume-driver=convoy ubuntu /bin/bash
    

    convoy 源码分析

    https://github.com/rancher/convoy/blob/master/daemon/daemon.go

    我们看一下,convoy都提供了哪些REST API

    CLI REST API

        m := map[string]map[string]requestHandler{
            "GET": {
                "/info":            s.doInfo,
                "/volumes/list":    s.doVolumeList,
                "/volumes/":        s.doVolumeInspect,
                "/snapshots/":      s.doSnapshotInspect,
                "/backups/list":    s.doBackupList,
                "/backups/inspect": s.doBackupInspect,
            },
            "POST": {
                "/volumes/create":   s.doVolumeCreate,
                "/volumes/mount":    s.doVolumeMount,
                "/volumes/umount":   s.doVolumeUmount,
                "/snapshots/create": s.doSnapshotCreate,
                "/backups/create":   s.doBackupCreate,
            },
            "DELETE": {
                "/volumes/":   s.doVolumeDelete,
                "/snapshots/": s.doSnapshotDelete,
                "/backups":    s.doBackupDelete,
            },
        }
    

    Volume-Plugin REST API

        pluginMap := map[string]map[string]http.HandlerFunc{
            "POST": {
                "/Plugin.Activate":           s.dockerActivate,
                "/VolumeDriver.Create":       s.dockerCreateVolume,
                "/VolumeDriver.Remove":       s.dockerRemoveVolume,
                "/VolumeDriver.Mount":        s.dockerMountVolume,
                "/VolumeDriver.Unmount":      s.dockerUnmountVolume,
                "/VolumeDriver.Path":         s.dockerVolumePath,
                "/VolumeDriver.Get":          s.dockerGetVolume,
                "/VolumeDriver.List":         s.dockerListVolume,
                "/VolumeDriver.Capabilities": s.dockerCapabilities,
            },
        }
    

    convoy daemon的启动参数

    [root@localhost ~]# convoy daemon --help
    NAME:
       convoy daemon - start convoy daemon
    
    USAGE:
       convoy daemon [command options] [arguments...]
    
    OPTIONS:
       --debug                          Debug log, enabled by default
       --log                            specific output log file, otherwise output to stdout by default
       --root "/var/lib/rancher/convoy"             specific root directory of convoy, if configure file exists, daemon specific options would be ignored
       --drivers [--drivers option --drivers option]        Drivers to be enabled, first driver in the list would be treated as default driver
       --driver-opts [--driver-opts option --driver-opts option]    options for driver
       --mnt-ns                             Specify mount namespace file descriptor if user don't want to mount in current namespace. Support by Device Mapper and EBS
       --ignore-docker-delete                   Do not delete volumes when told to by Docker
       --create-on-docker-mount                 Create a volume if docker asks to do a mount and the volume doesn't exist.
       --cmd-timeout                        Set timeout value for executing each command. One minute (1m) by default and at least one minute.
       --ignore-config-file                     Avoid loading the existing config file when starting daemon, and use the command line options instead (not including driver options)
    

    其中两个参数非常重要

    1. --root:
      specific root directory of convoy, if configure file exists, daemon specific options would be ignored
    2. --ignore-config-file:
      Avoid loading the existing config file when starting daemon, and use the command line options instead (not including driver options)

    相关文章

      网友评论

        本文标题:Docker卷插件

        本文链接:https://www.haomeiwen.com/subject/otijcctx.html