Plugins
By the end of this exercise, you should be able to:
- Install, configure, and delete any Docker plugin
- Use the
vieux/sshfsplugin to create ssh-mountable volumes that can be mounted into any container in your cluster
Installing a Plugin
Plugins can be hosted on Docker Store or any other (private) repository. Let's start with Docker Store. Browse to https://store.docker.com and enter
vieux/sshfsin the search box. The result should show you the plugin that we are going to work with.Install the plugin into our Docker Engine:
[centos@node-0 ~]$ docker plugin install vieux/sshfsThe system should ask us for permission to use privileges. In the case of the
sshfsplugin there are 4 privileges. Answer withy.Once we have successfully installed some plugins we can use the
lscommand to see the status of each of the installed plugins. Execute:[centos@node-0 ~]$ docker plugin ls
Enabling and Disabling a Plugin
Once a plugin is installed it is
enabledby default. We can disable it using this command:[centos@node-0 ~]$ docker plugin disable vieux/sshfsonly when a plugin is disabled can certain operations on it be executed.
The plugin can be (re-) enabled by using this command:
[centos@node-0 ~]$ docker plugin enable vieux/sshfsPlay with the above commands and notice how the status of the plugin changes when displaying it with
docker plugin ls.
Inspecting a Plugin
We can also use the
inspectcommand to further inspect all the attributes of a given plugin. Execute the following command:[centos@node-0 ~]$ docker plugin inspect vieux/sshfsand examine the output. Specifically note that there are two sections in the metadata called
Env, one is underConfigand the other underSettings. This is where the list of environment variables are listed that the author of the plugin has defined. In this specific situation we can see that there is a single variable calledDEBUGdefined. Its initial value is0.We can use the
setcommand to change values of the environment variables. Execute:[centos@node-0 ~]$ docker plugin set vieux/sshfs DEBUG=1 Error response from daemon: cannot set on an active plugin, disable plugin before settingThis is one of those times we have to disable the plugin first; do so, then try the
setcommand again:[centos@node-0 ~]$ docker plugin disable vieux/sshfs [centos@node-0 ~]$ docker plugin set vieux/sshfs DEBUG=1 [centos@node-0 ~]$ docker plugin enable vieux/sshfsand then inspect again the metadata of the plugin. Notice how the value of
DEBUGhas been adjusted. Only the one under theSettingsnode changed but the one under theConfignode still shows the original (default) value.
Using the Plugin
Make a directory on
node-1that we will mount as a volume across our cluster:[centos@node-1 ~]$ mkdir ~/demoBack on
node-0, use the plugin to create a volume that can be mounted via ssh:[centos@node-0 ~]$ docker volume create -d vieux/sshfs \ -o sshcmd=centos@<node-1 public IP>:/home/centos/demo \ -o password=orca \ sshvolumeMount that volume in a new container as per usual:
[centos@node-0 ~]$ docker container run --rm -it -v sshvolume:/data alpine shInside the container navigate to the
/datafolder and create a new file:/ # cd /data / # echo 'Hello from client!' > demo.txt / # ls -alHead over to
node-1, and confirm thatdemo.txtgot written there.
Removing a Plugin
If we don't want or need this plugin anymore we can remove it using the command:
[centos@node-0 ~]$ docker volume rm sshvolume [centos@node-0 ~]$ docker plugin disable vieux/sshfs [centos@node-0 ~]$ docker plugin rm vieux/sshfsNote how we first have to disable the plugin before we can remove it.
Conclusion
Docker follows a 'batteries included but swappable' mindset in its product design: everything you need to get started is included, but heavy customization is supported and encouraged. Docker plugins are one aspect of that flexibility, allowing users to define their own volume and networking behavior.