Introduction
In this lab, you will learn how to remove a Docker plugin using the docker plugin rm command. You will begin by installing a sample plugin to work with. Then, you will attempt to remove the plugin while it is still enabled to understand the default behavior and the error encountered.
Following the failed attempt, you will learn how to disable the plugin, which is a necessary prerequisite for removal. Finally, you will successfully remove the disabled plugin and also explore the option of using the force flag for removal.
Install a sample plugin
In this step, you will learn how to install a Docker plugin. Docker plugins extend the functionality of Docker, allowing you to integrate with external systems for things like storage, networking, and logging.
We will install a simple sample plugin to demonstrate the process. The command to install a plugin is docker plugin install. You will need to accept the plugin's capabilities and permissions during the installation.
First, let's install the vieux/sshfs plugin. This plugin allows you to use SSHFS for mounting volumes.
docker plugin install vieux/sshfs
You will be prompted to accept the plugin's capabilities. Type y and press Enter to proceed.
Plugin "vieux/sshfs" is requesting the following capabilities:
- Network: host
- Mounts: [/dev/fuse]
- Args: [--sshkey-path]
Do you grant the plugin these permissions? [y/N] y
After accepting, the plugin will be installed and enabled. You can verify the installation by listing the installed plugins.
docker plugin ls
You should see vieux/sshfs listed with the ENABLED status set to true.
Attempt to remove an enabled plugin
In the previous step, you installed and enabled the vieux/sshfs plugin. In this step, you will attempt to remove this plugin while it is still enabled. This will demonstrate that you cannot remove an enabled plugin directly.
The command to remove a Docker plugin is docker plugin rm. We will try to remove the vieux/sshfs plugin.
docker plugin rm vieux/sshfs
You will see an error message indicating that the plugin is enabled and cannot be removed. This is expected behavior, as Docker prevents you from removing a plugin that is currently in use or active.
The output will be similar to this:
Error response from daemon: plugin vieux/sshfs is enabled. Disable it before removing
This confirms that you must disable a plugin before you can remove it. In the next step, you will learn how to disable the plugin.
Disable the plugin
In the previous step, you learned that you cannot remove an enabled Docker plugin. To remove a plugin, you must first disable it.
The command to disable a Docker plugin is docker plugin disable. We will now disable the vieux/sshfs plugin that you installed in the first step.
docker plugin disable vieux/sshfs
This command will stop the plugin and make it inactive. You will not see much output if the command is successful.
To confirm that the plugin has been disabled, you can list the installed plugins again.
docker plugin ls
Now, the output for vieux/sshfs should show ENABLED as false.
ID NAME DESCRIPTION ENABLED
f51132325c3b vieux/sshfs Create SSHFS mounts true
Wait, the output still shows true? This is because the docker plugin ls command might show cached information. Let's try listing the plugins again to see the updated status.
docker plugin ls
Now you should see the ENABLED status for vieux/sshfs as false.
ID NAME DESCRIPTION ENABLED
f51132325c3b vieux/sshfs Create SSHFS mounts false
The plugin is now disabled and ready to be removed.
Remove the disabled plugin
In the previous step, you successfully disabled the vieux/sshfs plugin. Now that the plugin is disabled, you can remove it using the docker plugin rm command.
docker plugin rm vieux/sshfs
If the plugin was successfully removed, you will see the plugin name printed in the output.
vieux/sshfs
To confirm that the plugin has been removed, list the installed plugins again.
docker plugin ls
This time, the vieux/sshfs plugin should no longer appear in the list.
This demonstrates the standard process for removing a Docker plugin: first disable it, then remove it. In the next step, you will explore what happens if you try to force the removal of a plugin.
Attempt to remove the plugin using force
In the previous steps, you learned that you must disable a plugin before removing it. What happens if you try to force the removal of an enabled plugin?
The docker plugin rm command has a --force or -f flag that can be used to attempt to force the removal of a plugin. However, even with the force flag, Docker will not remove an enabled plugin.
Let's first reinstall the vieux/sshfs plugin so we have an enabled plugin to work with.
docker plugin install vieux/sshfs
Remember to type y and press Enter when prompted to accept the capabilities.
Now that the plugin is installed and enabled again, let's try to remove it using the force flag.
docker plugin rm --force vieux/sshfs
You will see a similar error message as when you tried to remove it without the force flag, indicating that the plugin is enabled and cannot be removed.
Error response from daemon: plugin vieux/sshfs is enabled. Disable it before removing
This confirms that the force flag does not override the requirement to disable a plugin before removal. The force flag is typically used in other Docker contexts, like removing containers, images, or volumes, to bypass certain checks, but it does not apply to removing enabled plugins.
To clean up, you can disable and remove the plugin again if you wish, following the steps you learned earlier.
Summary
In this lab, you learned how to install a Docker plugin using docker plugin install and verified its installation with docker plugin ls. You then attempted to remove an enabled plugin using docker plugin rm and discovered that Docker prevents the removal of active plugins, requiring them to be disabled first.



