github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/docs/extend/index.md (about) 1 --- 2 advisory: experimental 3 aliases: 4 - /engine/extend/ 5 description: Develop and use a plugin with the managed plugin system 6 keywords: 7 - API, Usage, plugins, documentation, developer 8 title: Managed plugin system 9 --- 10 11 <!-- This file is maintained within the docker/docker Github 12 repository at https://github.com/docker/docker/. Make all 13 pull requests against that repo. If you see this file in 14 another repository, consider it read-only there, as it will 15 periodically be overwritten by the definitive file. Pull 16 requests which include edits to this file in other repositories 17 will be rejected. 18 --> 19 20 # Docker Engine managed plugin system 21 22 This document describes the plugin system available today in the **experimental 23 build** of Docker 1.12: 24 25 * [Installing and using a plugin](index.md#installing-and-using-a-plugin) 26 * [Developing a plugin](index.md#developing-a-plugin) 27 28 Docker Engine's plugins system allows you to install, start, stop, and remove 29 plugins using Docker Engine. This mechanism is currently only available for 30 volume drivers, but more plugin driver types will be available in future releases. 31 32 For information about the legacy plugin system available in Docker Engine 1.12 33 and earlier, see [Understand legacy Docker Engine plugins](legacy_plugins.md). 34 35 ## Installing and using a plugin 36 37 Plugins are distributed as Docker images and can be hosted on Docker Hub or on 38 a private registry. 39 40 To install a plugin, use the `docker plugin install` command, which pulls the 41 plugin from Docker hub or your private registry, prompts you to grant 42 permissions or capabilities if necessary, and enables the plugin. 43 44 To check the status of installed plugins, use the `docker plugin ls` command. 45 Plugins that start successfully are listed as enabled in the output. 46 47 After a plugin is installed, you can use it as an option for another Docker 48 operation, such as creating a volume. 49 50 In the following example, you install the `sshfs` plugin, verify that it is 51 enabled, and use it to create a volume. 52 53 1. Install the `sshfs` plugin. 54 55 ```bash 56 $ docker plugin install vieux/sshfs 57 58 Plugin "vieux/sshfs" is requesting the following privileges: 59 - network: [host] 60 - capabilities: [CAP_SYS_ADMIN] 61 Do you grant the above permissions? [y/N] y 62 63 vieux/sshfs 64 ``` 65 66 The plugin requests 2 privileges: 67 - It needs access to the `host` network. 68 - It needs the `CAP_SYS_ADMIN` capability, which allows the plugin to run 69 the `mount` command. 70 71 2. Check that the plugin is enabled in the output of `docker plugin ls`. 72 73 ```bash 74 $ docker plugin ls 75 76 NAME TAG ENABLED 77 vieux/sshfs latest true 78 ``` 79 80 3. Create a volume using the plugin. 81 This example mounts the `/remote` directory on host `1.2.3.4` into a 82 volume named `sshvolume`. This volume can now be mounted into containers. 83 84 ```bash 85 $ docker volume create \ 86 -d vieux/sshfs \ 87 --name sshvolume \ 88 -o sshcmd=user@1.2.3.4:/remote 89 90 sshvolume 91 ``` 92 4. Verify that the volume was created successfully. 93 94 ```bash 95 $ docker volume ls 96 97 DRIVER NAME 98 vieux/sshfs sshvolume 99 ``` 100 101 5. Start a container that uses the volume `sshvolume`. 102 103 ```bash 104 $ docker run -v sshvolume:/data busybox ls /data 105 106 <content of /remote on machine 1.2.3.4> 107 ``` 108 109 To disable a plugin, use the `docker plugin disable` command. To completely 110 remove it, use the `docker plugin remove` command. For other available 111 commands and options, see the 112 [command line reference](../reference/commandline/index.md). 113 114 ## Developing a plugin 115 116 Currently, there are no CLI commands available to help you develop a plugin. 117 This is expected to change in a future release. The manual process for creating 118 plugins is described in this section. 119 120 ### Plugin location and files 121 122 Plugins are stored in `/var/lib/docker/plugins`. The `plugins.json` file lists 123 each plugin's configuration, and each plugin is stored in a directory with a 124 unique identifier. 125 126 ```bash 127 # ls -la /var/lib/docker/plugins 128 total 20 129 drwx------ 4 root root 4096 Aug 8 18:03 . 130 drwx--x--x 12 root root 4096 Aug 8 17:53 .. 131 drwxr-xr-x 3 root root 4096 Aug 8 17:56 cd851ce43a403 132 -rw------- 1 root root 2107 Aug 8 18:03 plugins.json 133 ``` 134 135 ### Format of plugins.json 136 137 The `plugins.json` is an inventory of all installed plugins. This example shows 138 a `plugins.json` with a single plugin installed. 139 140 ```json 141 # cat plugins.json 142 { 143 "cd851ce43a403": { 144 "plugin": { 145 "Manifest": { 146 "Args": { 147 "Value": null, 148 "Settable": null, 149 "Description": "", 150 "Name": "" 151 }, 152 "Env": null, 153 "Devices": null, 154 "Mounts": null, 155 "Capabilities": [ 156 "CAP_SYS_ADMIN" 157 ], 158 "ManifestVersion": "v0", 159 "Description": "sshFS plugin for Docker", 160 "Documentation": "https://docs.docker.com/engine/extend/plugins/", 161 "Interface": { 162 "Socket": "sshfs.sock", 163 "Types": [ 164 "docker.volumedriver/1.0" 165 ] 166 }, 167 "Entrypoint": [ 168 "/go/bin/docker-volume-sshfs" 169 ], 170 "Workdir": "", 171 "User": {}, 172 "Network": { 173 "Type": "host" 174 } 175 }, 176 "Config": { 177 "Devices": null, 178 "Args": null, 179 "Env": [], 180 "Mounts": [] 181 }, 182 "Active": true, 183 "Tag": "latest", 184 "Name": "vieux/sshfs", 185 "Id": "cd851ce43a403" 186 } 187 } 188 } 189 ``` 190 191 ### Contents of a plugin directory 192 193 Each directory within `/var/lib/docker/plugins/` contains a `rootfs` directory 194 and two JSON files. 195 196 ```bash 197 # ls -la /var/lib/docker/plugins/cd851ce43a403 198 total 12 199 drwx------ 19 root root 4096 Aug 8 17:56 rootfs 200 -rw-r--r-- 1 root root 50 Aug 8 17:56 plugin-config.json 201 -rw------- 1 root root 347 Aug 8 17:56 manifest.json 202 ``` 203 204 #### The rootfs directory 205 The `rootfs` directory represents the root filesystem of the plugin. In this 206 example, it was created from a Dockerfile: 207 208 >**Note:** The `/run/docker/plugins` directory is mandatory for docker to communicate with 209 the plugin. 210 211 ```bash 212 $ git clone https://github.com/vieux/docker-volume-sshfs 213 $ cd docker-volume-sshfs 214 $ docker build -t rootfs . 215 $ id=$(docker create rootfs true) # id was cd851ce43a403 when the image was created 216 $ sudo mkdir -p /var/lib/docker/plugins/$id/rootfs 217 $ sudo docker export "$id" | sudo tar -x -C /var/lib/docker/plugins/$id/rootfs 218 $ sudo chgrp -R docker /var/lib/docker/plugins/ 219 $ docker rm -vf "$id" 220 $ docker rmi rootfs 221 ``` 222 223 #### The manifest.json and plugin-config.json files 224 225 The `manifest.json` file describes the plugin. The `plugin-config.json` file 226 contains runtime parameters and is only required if your plugin has runtime 227 parameters. [See the Plugins Manifest reference](manifest.md). 228 229 Consider the following `manifest.json` file. 230 231 ```json 232 { 233 "manifestVersion": "v0", 234 "description": "sshFS plugin for Docker", 235 "documentation": "https://docs.docker.com/engine/extend/plugins/", 236 "entrypoint": ["/go/bin/docker-volume-sshfs"], 237 "network": { 238 "type": "host" 239 }, 240 "interface" : { 241 "types": ["docker.volumedriver/1.0"], 242 "socket": "sshfs.sock" 243 }, 244 "capabilities": ["CAP_SYS_ADMIN"] 245 } 246 ``` 247 248 This plugin is a volume driver. It requires a `host` network and the 249 `CAP_SYS_ADMIN` capability. It depends upon the `/go/bin/docker-volume-sshfs` 250 entrypoint and uses the `/run/docker/plugins/sshfs.sock` socket to communicate 251 with Docker Engine. 252 253 254 Consider the following `plugin-config.json` file. 255 256 ```json 257 { 258 "Devices": null, 259 "Args": null, 260 "Env": [], 261 "Mounts": [] 262 } 263 ``` 264 265 This plugin has no runtime parameters. 266 267 Each of these JSON files is included as part of `plugins.json`, as you can see 268 by looking back at the example above. After a plugin is installed, `manifest.json` 269 is read-only, but `plugin-config.json` is read-write, and includes all runtime 270 configuration options for the plugin. 271 272 ### Creating the plugin 273 274 Follow these steps to create a plugin: 275 276 1. Choose a name for the plugin. Plugin name uses the same format as images, 277 for example: `<repo_name>/<name>`. 278 279 2. Create a `rootfs` and export it to `/var/lib/docker/plugins/$id/rootfs` 280 using `docker export`. See [The rootfs directory](#the-rootfs-directory) for 281 an example of creating a `rootfs`. 282 283 3. Create a `manifest.json` file in `/var/lib/docker/plugins/$id/`. 284 285 4. Create a `plugin-config.json` file if needed. 286 287 5. Create or add a section to `/var/lib/docker/plugins/plugins.json`. Use 288 `<user>/<name>` as “Name” and `$id` as “Id”. 289 290 6. Restart the Docker Engine service. 291 292 7. Run `docker plugin ls`. 293 * If your plugin is enabled, you can push it to the 294 registry. 295 * If the plugin is not listed or is disabled, something went wrong. 296 Check the daemon logs for errors. 297 298 8. If you are not already logged in, use `docker login` to authenticate against 299 the registry so that you can push to it. 300 301 9. Run `docker plugin push <repo_name>/<name>` to push the plugin. 302 303 The plugin can now be used by any user with access to your registry.