2016-10-14 18:30:36 -04:00
|
|
|
---
|
2016-10-20 14:12:02 -04:00
|
|
|
description: Develop and use a plugin with the managed plugin system
|
2016-11-03 17:21:33 -04:00
|
|
|
keywords: "API, Usage, plugins, documentation, developer"
|
2016-10-20 14:12:02 -04:00
|
|
|
title: Managed plugin system
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
<!-- This file is maintained within the docker/docker Github
|
|
|
|
repository at https://github.com/docker/docker/. Make all
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
will be rejected.
|
|
|
|
-->
|
|
|
|
|
2016-08-29 19:37:01 -04:00
|
|
|
# Docker Engine managed plugin system
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
* [Installing and using a plugin](index.md#installing-and-using-a-plugin)
|
|
|
|
* [Developing a plugin](index.md#developing-a-plugin)
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
Docker Engine's plugins system allows you to install, start, stop, and remove
|
|
|
|
plugins using Docker Engine. This mechanism is currently only available for
|
|
|
|
volume drivers, but more plugin driver types will be available in future releases.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
For information about the legacy plugin system available in Docker Engine 1.12
|
|
|
|
and earlier, see [Understand legacy Docker Engine plugins](legacy_plugins.md).
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-11-22 10:01:14 -05:00
|
|
|
> **Note**: Docker Engine managed plugins are currently not supported
|
|
|
|
on Windows daemons.
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
## Installing and using a plugin
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
Plugins are distributed as Docker images and can be hosted on Docker Hub or on
|
|
|
|
a private registry.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
To install a plugin, use the `docker plugin install` command, which pulls the
|
|
|
|
plugin from Docker hub or your private registry, prompts you to grant
|
|
|
|
permissions or capabilities if necessary, and enables the plugin.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
To check the status of installed plugins, use the `docker plugin ls` command.
|
|
|
|
Plugins that start successfully are listed as enabled in the output.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
After a plugin is installed, you can use it as an option for another Docker
|
|
|
|
operation, such as creating a volume.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
In the following example, you install the `sshfs` plugin, verify that it is
|
|
|
|
enabled, and use it to create a volume.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
1. Install the `sshfs` plugin.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker plugin install vieux/sshfs
|
|
|
|
|
|
|
|
Plugin "vieux/sshfs" is requesting the following privileges:
|
|
|
|
- network: [host]
|
|
|
|
- capabilities: [CAP_SYS_ADMIN]
|
|
|
|
Do you grant the above permissions? [y/N] y
|
|
|
|
|
|
|
|
vieux/sshfs
|
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
The plugin requests 2 privileges:
|
|
|
|
- It needs access to the `host` network.
|
|
|
|
- It needs the `CAP_SYS_ADMIN` capability, which allows the plugin to run
|
|
|
|
the `mount` command.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
2. Check that the plugin is enabled in the output of `docker plugin ls`.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker plugin ls
|
|
|
|
|
|
|
|
NAME TAG ENABLED
|
|
|
|
vieux/sshfs latest true
|
|
|
|
```
|
|
|
|
|
2016-10-18 06:01:46 -04:00
|
|
|
3. Create a volume using the plugin.
|
2016-10-20 14:12:02 -04:00
|
|
|
This example mounts the `/remote` directory on host `1.2.3.4` into a
|
|
|
|
volume named `sshvolume`. This volume can now be mounted into containers.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker volume create \
|
|
|
|
-d vieux/sshfs \
|
|
|
|
--name sshvolume \
|
|
|
|
-o sshcmd=user@1.2.3.4:/remote
|
|
|
|
|
|
|
|
sshvolume
|
|
|
|
```
|
2016-10-20 14:12:02 -04:00
|
|
|
4. Verify that the volume was created successfully.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
2016-10-20 14:12:02 -04:00
|
|
|
$ docker volume ls
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
DRIVER NAME
|
|
|
|
vieux/sshfs sshvolume
|
2016-08-16 14:53:36 -04:00
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
5. Start a container that uses the volume `sshvolume`.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
2016-10-20 14:12:02 -04:00
|
|
|
$ docker run -v sshvolume:/data busybox ls /data
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
<content of /remote on machine 1.2.3.4>
|
2016-08-16 14:53:36 -04:00
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
To disable a plugin, use the `docker plugin disable` command. To completely
|
|
|
|
remove it, use the `docker plugin remove` command. For other available
|
|
|
|
commands and options, see the
|
|
|
|
[command line reference](../reference/commandline/index.md).
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
## Developing a plugin
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
Currently, there are no CLI commands available to help you develop a plugin.
|
|
|
|
This is expected to change in a future release. The manual process for creating
|
|
|
|
plugins is described in this section.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
### Plugin location and files
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
Plugins are stored in `/var/lib/docker/plugins`. The `plugins.json` file lists
|
|
|
|
each plugin's configuration, and each plugin is stored in a directory with a
|
|
|
|
unique identifier.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# ls -la /var/lib/docker/plugins
|
|
|
|
total 20
|
|
|
|
drwx------ 4 root root 4096 Aug 8 18:03 .
|
|
|
|
drwx--x--x 12 root root 4096 Aug 8 17:53 ..
|
|
|
|
drwxr-xr-x 3 root root 4096 Aug 8 17:56 cd851ce43a403
|
|
|
|
-rw------- 1 root root 2107 Aug 8 18:03 plugins.json
|
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
### Format of plugins.json
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
The `plugins.json` is an inventory of all installed plugins. This example shows
|
|
|
|
a `plugins.json` with a single plugin installed.
|
|
|
|
|
|
|
|
```json
|
2016-08-16 14:53:36 -04:00
|
|
|
# cat plugins.json
|
|
|
|
{
|
|
|
|
"cd851ce43a403": {
|
|
|
|
"plugin": {
|
2016-11-07 21:51:47 -05:00
|
|
|
"Config": {
|
2016-08-16 14:53:36 -04:00
|
|
|
"Args": {
|
|
|
|
"Value": null,
|
|
|
|
"Settable": null,
|
|
|
|
"Description": "",
|
|
|
|
"Name": ""
|
|
|
|
},
|
|
|
|
"Env": null,
|
|
|
|
"Devices": null,
|
|
|
|
"Mounts": null,
|
|
|
|
"Capabilities": [
|
|
|
|
"CAP_SYS_ADMIN"
|
|
|
|
],
|
|
|
|
"Description": "sshFS plugin for Docker",
|
|
|
|
"Documentation": "https://docs.docker.com/engine/extend/plugins/",
|
|
|
|
"Interface": {
|
|
|
|
"Socket": "sshfs.sock",
|
|
|
|
"Types": [
|
|
|
|
"docker.volumedriver/1.0"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"Entrypoint": [
|
|
|
|
"/go/bin/docker-volume-sshfs"
|
|
|
|
],
|
|
|
|
"Workdir": "",
|
|
|
|
"User": {},
|
|
|
|
"Network": {
|
|
|
|
"Type": "host"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"Config": {
|
|
|
|
"Devices": null,
|
|
|
|
"Args": null,
|
|
|
|
"Env": [],
|
|
|
|
"Mounts": []
|
|
|
|
},
|
|
|
|
"Active": true,
|
|
|
|
"Tag": "latest",
|
|
|
|
"Name": "vieux/sshfs",
|
|
|
|
"Id": "cd851ce43a403"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
### Contents of a plugin directory
|
|
|
|
|
|
|
|
Each directory within `/var/lib/docker/plugins/` contains a `rootfs` directory
|
|
|
|
and two JSON files.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
|
|
|
# ls -la /var/lib/docker/plugins/cd851ce43a403
|
|
|
|
total 12
|
|
|
|
drwx------ 19 root root 4096 Aug 8 17:56 rootfs
|
2016-11-07 21:51:47 -05:00
|
|
|
-rw-r--r-- 1 root root 50 Aug 8 17:56 plugin-settings.json
|
|
|
|
-rw------- 1 root root 347 Aug 8 17:56 config.json
|
2016-08-16 14:53:36 -04:00
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
#### The rootfs directory
|
|
|
|
The `rootfs` directory represents the root filesystem of the plugin. In this
|
|
|
|
example, it was created from a Dockerfile:
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-25 16:39:04 -04:00
|
|
|
>**Note:** The `/run/docker/plugins` directory is mandatory inside of the
|
|
|
|
plugin's filesystem for docker to communicate with the plugin.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
|
|
|
```bash
|
2016-08-23 22:09:33 -04:00
|
|
|
$ git clone https://github.com/vieux/docker-volume-sshfs
|
2016-08-16 14:53:36 -04:00
|
|
|
$ cd docker-volume-sshfs
|
|
|
|
$ docker build -t rootfs .
|
|
|
|
$ id=$(docker create rootfs true) # id was cd851ce43a403 when the image was created
|
2016-10-20 14:12:02 -04:00
|
|
|
$ sudo mkdir -p /var/lib/docker/plugins/$id/rootfs
|
|
|
|
$ sudo docker export "$id" | sudo tar -x -C /var/lib/docker/plugins/$id/rootfs
|
|
|
|
$ sudo chgrp -R docker /var/lib/docker/plugins/
|
2016-08-16 14:53:36 -04:00
|
|
|
$ docker rm -vf "$id"
|
|
|
|
$ docker rmi rootfs
|
|
|
|
```
|
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
#### The config.json and plugin-settings.json files
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
The `config.json` file describes the plugin. The `plugin-settings.json` file
|
2016-10-20 14:12:02 -04:00
|
|
|
contains runtime parameters and is only required if your plugin has runtime
|
2016-11-07 21:51:47 -05:00
|
|
|
parameters. [See the Plugins Config reference](config.md).
|
2016-10-20 14:12:02 -04:00
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
Consider the following `config.json` file.
|
2016-10-20 14:12:02 -04:00
|
|
|
|
|
|
|
```json
|
2016-08-16 14:53:36 -04:00
|
|
|
{
|
|
|
|
"description": "sshFS plugin for Docker",
|
|
|
|
"documentation": "https://docs.docker.com/engine/extend/plugins/",
|
|
|
|
"entrypoint": ["/go/bin/docker-volume-sshfs"],
|
|
|
|
"network": {
|
|
|
|
"type": "host"
|
|
|
|
},
|
2016-09-07 05:34:57 -04:00
|
|
|
"interface" : {
|
|
|
|
"types": ["docker.volumedriver/1.0"],
|
|
|
|
"socket": "sshfs.sock"
|
|
|
|
},
|
|
|
|
"capabilities": ["CAP_SYS_ADMIN"]
|
2016-08-16 14:53:36 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
This plugin is a volume driver. It requires a `host` network and the
|
|
|
|
`CAP_SYS_ADMIN` capability. It depends upon the `/go/bin/docker-volume-sshfs`
|
|
|
|
entrypoint and uses the `/run/docker/plugins/sshfs.sock` socket to communicate
|
|
|
|
with Docker Engine.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
Consider the following `plugin-settings.json` file.
|
2016-10-20 14:12:02 -04:00
|
|
|
|
|
|
|
```json
|
2016-08-16 14:53:36 -04:00
|
|
|
{
|
|
|
|
"Devices": null,
|
|
|
|
"Args": null,
|
|
|
|
"Env": [],
|
|
|
|
"Mounts": []
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
This plugin has no runtime parameters.
|
|
|
|
|
|
|
|
Each of these JSON files is included as part of `plugins.json`, as you can see
|
2016-11-07 21:51:47 -05:00
|
|
|
by looking back at the example above. After a plugin is installed, `config.json`
|
|
|
|
is read-only, but `plugin-settings.json` is read-write, and includes all runtime
|
2016-10-20 14:12:02 -04:00
|
|
|
configuration options for the plugin.
|
|
|
|
|
|
|
|
### Creating the plugin
|
|
|
|
|
|
|
|
Follow these steps to create a plugin:
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
1. Choose a name for the plugin. Plugin name uses the same format as images,
|
|
|
|
for example: `<repo_name>/<name>`.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-10-20 14:12:02 -04:00
|
|
|
2. Create a `rootfs` and export it to `/var/lib/docker/plugins/$id/rootfs`
|
|
|
|
using `docker export`. See [The rootfs directory](#the-rootfs-directory) for
|
|
|
|
an example of creating a `rootfs`.
|
2016-08-16 14:53:36 -04:00
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
3. Create a `config.json` file in `/var/lib/docker/plugins/$id/`.
|
2016-10-20 14:12:02 -04:00
|
|
|
|
2016-11-07 21:51:47 -05:00
|
|
|
4. Create a `plugin-settings.json` file if needed.
|
2016-10-20 14:12:02 -04:00
|
|
|
|
|
|
|
5. Create or add a section to `/var/lib/docker/plugins/plugins.json`. Use
|
2016-08-16 14:53:36 -04:00
|
|
|
`<user>/<name>` as “Name” and `$id` as “Id”.
|
2016-10-20 14:12:02 -04:00
|
|
|
|
|
|
|
6. Restart the Docker Engine service.
|
|
|
|
|
|
|
|
7. Run `docker plugin ls`.
|
|
|
|
* If your plugin is enabled, you can push it to the
|
|
|
|
registry.
|
|
|
|
* If the plugin is not listed or is disabled, something went wrong.
|
|
|
|
Check the daemon logs for errors.
|
|
|
|
|
|
|
|
8. If you are not already logged in, use `docker login` to authenticate against
|
|
|
|
the registry so that you can push to it.
|
|
|
|
|
|
|
|
9. Run `docker plugin push <repo_name>/<name>` to push the plugin.
|
|
|
|
|
|
|
|
The plugin can now be used by any user with access to your registry.
|