github.com/dpiddy/docker@v1.12.2-rc1/docs/extend/index.md (about) 1 <!--[metadata]> 2 +++ 3 aliases = [ 4 "/engine/extend/" 5 ] 6 title = "Managed plugin system" 7 description = "How develop and use a plugin with the managed plugin system" 8 keywords = ["API, Usage, plugins, documentation, developer"] 9 advisory = "experimental" 10 [menu.main] 11 parent = "engine_extend" 12 weight=1 13 +++ 14 <![end-metadata]--> 15 16 # Docker Engine managed plugin system 17 18 This document describes the plugin system available today in the **experimental 19 build** of Docker 1.12: 20 21 * [How to operate an existing plugin](#how-to-operate-a-plugin) 22 * [How to develop a plugin](#how-to-develop-a-plugin) 23 24 Unlike the legacy plugin system, you now manage plugins using Docker Engine: 25 26 * install plugins 27 * start plugins 28 * stop plugins 29 * remove plugins 30 31 The current Docker Engine plugin system only supports volume drivers. We are 32 adding more plugin driver types in the future releases. 33 34 For information on Docker Engine plugins generally available in Docker Engine 35 1.12 and earlier, refer to [Understand legacy Docker Engine plugins](legacy_plugins.md). 36 37 ## How to operate a plugin 38 39 Plugins are distributed as Docker images, so develpers can host them on Docker 40 Hub or on a private registry. 41 42 You install the plugin using a single command: `docker plugin install <PLUGIN>`. 43 The `plugin install` command pulls the plugin from the Docker Hub or private 44 registry. If necessary the CLI prompts you to accept any privilige requriements. 45 For example the plugin may require access to a device on the host system. 46 Finally it enables the plugin. 47 48 Run `docker plugin ls` to check the status of installed plugins. The Engine 49 markes plugins that are started without issues as `ENABLED`. 50 51 After you install a plugin, the plugin behavior is the same as legacy plugins. 52 The following example demonstrates how to install the `sshfs` plugin and use it 53 to create a volume. 54 55 1. Install the `sshfs` plugin. 56 57 ```bash 58 $ docker plugin install vieux/sshfs 59 60 Plugin "vieux/sshfs" is requesting the following privileges: 61 - network: [host] 62 - capabilities: [CAP_SYS_ADMIN] 63 Do you grant the above permissions? [y/N] y 64 65 vieux/sshfs 66 ``` 67 68 The plugin requests 2 privileges, the `CAP_SYS_ADMIN` capability to be able 69 to do mount inside the plugin and `host networking`. 70 71 2. Check for a value of `true` the `ENABLED` column to verify the plugin 72 started without error. 73 74 ```bash 75 $ docker plugin ls 76 77 NAME TAG ENABLED 78 vieux/sshfs latest true 79 ``` 80 81 3. Create a volume using the plugin. 82 83 ```bash 84 $ docker volume create \ 85 -d vieux/sshfs \ 86 --name sshvolume \ 87 -o sshcmd=user@1.2.3.4:/remote 88 89 sshvolume 90 ``` 91 92 4. Use the volume `sshvolume`. 93 94 ```bash 95 $ docker run -v sshvolume:/data busybox ls /data 96 97 <content of /remote on machine 1.2.3.4> 98 ``` 99 100 5. Verify the plugin successfully created the volume. 101 102 ```bash 103 $ docker volume ls 104 105 DRIVER NAME 106 vieux/sshfs sshvolume 107 ``` 108 109 You can stop a plugin with the `docker plugin disable` 110 command or remove a plugin with `docker plugin remove`. 111 112 See the [command line reference](../reference/commandline/index.md) for more 113 information. 114 115 ## How to develop a plugin 116 117 Plugin creation is currently a manual process. We plan to add automation in a 118 future release with a command such as `docker plugin build`. 119 120 This section describes the format of an existing enabled plugin. You have to 121 create and format the plugin files by hand. 122 123 Plugins are stored in `/var/lib/docker/plugins`. For instance: 124 125 ```bash 126 # ls -la /var/lib/docker/plugins 127 total 20 128 drwx------ 4 root root 4096 Aug 8 18:03 . 129 drwx--x--x 12 root root 4096 Aug 8 17:53 .. 130 drwxr-xr-x 3 root root 4096 Aug 8 17:56 cd851ce43a403 131 -rw------- 1 root root 2107 Aug 8 18:03 plugins.json 132 ``` 133 134 `plugins.json` is an inventory of all installed plugins. For example: 135 136 ```bash 137 # cat plugins.json 138 { 139 "cd851ce43a403": { 140 "plugin": { 141 "Manifest": { 142 "Args": { 143 "Value": null, 144 "Settable": null, 145 "Description": "", 146 "Name": "" 147 }, 148 "Env": null, 149 "Devices": null, 150 "Mounts": null, 151 "Capabilities": [ 152 "CAP_SYS_ADMIN" 153 ], 154 "ManifestVersion": "v0.1", 155 "Description": "sshFS plugin for Docker", 156 "Documentation": "https://docs.docker.com/engine/extend/plugins/", 157 "Interface": { 158 "Socket": "sshfs.sock", 159 "Types": [ 160 "docker.volumedriver/1.0" 161 ] 162 }, 163 "Entrypoint": [ 164 "/go/bin/docker-volume-sshfs" 165 ], 166 "Workdir": "", 167 "User": {}, 168 "Network": { 169 "Type": "host" 170 } 171 }, 172 "Config": { 173 "Devices": null, 174 "Args": null, 175 "Env": [], 176 "Mounts": [] 177 }, 178 "Active": true, 179 "Tag": "latest", 180 "Name": "vieux/sshfs", 181 "Id": "cd851ce43a403" 182 } 183 } 184 } 185 ``` 186 187 Each folder represents a plugin. For example: 188 189 ```bash 190 # ls -la /var/lib/docker/plugins/cd851ce43a403 191 total 12 192 drwx------ 19 root root 4096 Aug 8 17:56 rootfs 193 -rw-r--r-- 1 root root 50 Aug 8 17:56 plugin-config.json 194 -rw------- 1 root root 347 Aug 8 17:56 manifest.json 195 ``` 196 197 `rootfs` represents the root filesystem of the plugin. In this example, it was 198 created from a Dockerfile as follows: 199 200 >**Note:** `/run/docker/plugins` is mandatory for docker to communicate with 201 the plugin._ 202 203 ```bash 204 $ git clone https://github.com/vieux/docker-volume-sshfs 205 $ cd docker-volume-sshfs 206 $ docker build -t rootfs . 207 $ id=$(docker create rootfs true) # id was cd851ce43a403 when the image was created 208 $ mkdir -p /var/lib/docker/plugins/$id/rootfs 209 $ docker export "$id" | tar -x -C /var/lib/docker/plugins/$id/rootfs 210 $ docker rm -vf "$id" 211 $ docker rmi rootfs 212 ``` 213 214 `manifest.json` describes the plugin and `plugin-config.json` contains some 215 runtime parameters. For example: 216 217 ```bash 218 # cat manifest.json 219 { 220 "manifestVersion": "v0.1", 221 "description": "sshFS plugin for Docker", 222 "documentation": "https://docs.docker.com/engine/extend/plugins/", 223 "entrypoint": ["/go/bin/docker-volume-sshfs"], 224 "network": { 225 "type": "host" 226 }, 227 "interface" : { 228 "types": ["docker.volumedriver/1.0"], 229 "socket": "sshfs.sock" 230 }, 231 "capabilities": ["CAP_SYS_ADMIN"] 232 } 233 ``` 234 235 In this example, you can see the plugin is a volume driver, requires the 236 `CAP_SYS_ADMIN` capability, `host networking`, `/go/bin/docker-volume-sshfs` as 237 entrypoint and is going to use `/run/docker/plugins/sshfs.sock` to communicate 238 with the Docker Engine. 239 240 ```bash 241 # cat plugin-config.json 242 { 243 "Devices": null, 244 "Args": null, 245 "Env": [], 246 "Mounts": [] 247 } 248 ``` 249 250 This plugin doesn't require runtime parameters. 251 252 Both `manifest.json` and `plugin-config.json` are part of the `plugins.json`. 253 `manifest.json` is read-only and `plugin-config.json` is read-write. 254 255 To summarize, follow the steps below to create a plugin: 256 257 0. Choose a name for the plugin. Plugin name uses the same format as images, 258 for example: `<repo_name>/<name>`. 259 1. Create a rootfs in `/var/lib/docker/plugins/$id/rootfs`. 260 2. Create manifest.json file in `/var/lib/docker/plugins/$id/`. 261 3. Create a `plugin-config.json` if needed. 262 4. Create or add a section to `/var/lib/docker/plugins/plugins.json`. Use 263 `<user>/<name>` as “Name” and `$id` as “Id”. 264 5. Restart the Docker Engine. 265 6. Run `docker plugin ls`. 266 * If your plugin is listed as `ENABLED=true`, you can push it to the 267 registry. 268 * If the plugin is not listed or if `ENABLED=false`, something went wrong. 269 Check the daemon logs for errors. 270 7. If you are not already logged in, use `docker login` to authenticate against 271 a registry. 272 8. Run `docker plugin push <repo_name>/<name>` to push the plugin.