How to use docker plugin disable command to disable a plugin

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to manage Docker plugins by focusing on the docker plugin disable command. You will begin by listing the currently installed plugins to understand their status. Following this, you will practice disabling a plugin, observing the effect of this action.

The lab will also cover how to verify that a plugin has been successfully disabled. Optionally, you will explore scenarios where disabling a plugin might be restricted, such as when it has active references, and how to potentially force disable an active plugin.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker(("Docker")) -.-> docker/VolumeOperationsGroup(["Volume Operations"]) docker/ContainerOperationsGroup -.-> docker/ls("List Containers") docker/ContainerOperationsGroup -.-> docker/rm("Remove Container") docker/VolumeOperationsGroup -.-> docker/volume("Manage Volumes") subgraph Lab Skills docker/ls -.-> lab-555188{{"How to use docker plugin disable command to disable a plugin"}} docker/rm -.-> lab-555188{{"How to use docker plugin disable command to disable a plugin"}} docker/volume -.-> lab-555188{{"How to use docker plugin disable command to disable a plugin"}} end

List installed plugins

In this step, you will learn how to list the Docker plugins that are currently installed on your system. Docker plugins extend the functionality of Docker, providing features like volume management, networking, and logging.

To list the installed plugins, you can use the docker plugin ls command. This command will show you a list of all installed plugins, along with their status (enabled or disabled), and other relevant information.

Let's execute the command to see the installed plugins.

docker plugin ls

You should see output similar to this, although the specific plugins listed may vary depending on your environment:

ID    NAME    DESCRIPTION    ENABLED

In a default LabEx environment, there might not be any plugins installed by default. The output above indicates that no plugins are currently installed. If you had plugins installed, they would be listed here.

The output columns are:

  • ID: The unique identifier of the plugin.
  • NAME: The name of the plugin.
  • DESCRIPTION: A brief description of the plugin's functionality.
  • ENABLED: Indicates whether the plugin is currently enabled (true) or disabled (false).

Understanding which plugins are installed and their status is the first step in managing Docker plugins. In the following steps, you will learn how to disable and manage these plugins.

Disable a plugin

In this step, you will learn how to disable an installed Docker plugin. Disabling a plugin stops it from running and makes its functionality unavailable to Docker.

To disable a plugin, you use the docker plugin disable command followed by the name or ID of the plugin you want to disable.

Since there are no plugins installed by default in this environment, we will first install a simple plugin to demonstrate the disable command. We will install the vieux/sshfs plugin, which allows mounting remote SSH filesystems as Docker volumes.

First, let's install the plugin. This command will pull the plugin image and enable it.

docker plugin install vieux/sshfs

You will be prompted to confirm the plugin's capabilities. Type y and press Enter to proceed.

Plugin "vieux/sshfs" is requesting the following privileges:
 - network: [host]
 - mount: [/dev/fuse]
 - allow-host-dnsserver: true
 - allow-other: true
 - capability: [CAP_SYS_ADMIN]
Do you grant the plugin these privileges? [y/n] y

After the installation is complete, you can verify that the plugin is installed and enabled by listing the plugins again:

docker plugin ls

You should now see vieux/sshfs listed with ENABLED set to true.

ID                  NAME                DESCRIPTION                         ENABLED
<plugin_id>         vieux/sshfs         Mount remote SSH filesystem         true

Now, let's disable the vieux/sshfs plugin using its name:

docker plugin disable vieux/sshfs

If the command is successful, you will not see any output. This indicates that the plugin has been disabled.

Disabling a plugin is useful when you no longer need its functionality or if you are troubleshooting issues. In the next step, you will verify that the plugin is indeed disabled.

Verify the plugin is disabled

In this step, you will verify that the vieux/sshfs plugin you disabled in the previous step is indeed no longer enabled.

To check the status of installed plugins, you can use the docker plugin ls command again. This command will show the current state of all plugins.

Execute the command:

docker plugin ls

Look at the output for the vieux/sshfs plugin. The ENABLED column should now show false.

ID                  NAME                DESCRIPTION                         ENABLED
<plugin_id>         vieux/sshfs         Mount remote SSH filesystem         false

Seeing false in the ENABLED column confirms that the plugin has been successfully disabled. When a plugin is disabled, Docker cannot use its functionality.

This verification step is important to ensure that your previous command had the desired effect. In the next optional steps, you will explore scenarios where disabling a plugin might be more complex.

Attempt to disable a plugin with references (optional)

In this optional step, you will attempt to disable a plugin that is currently in use or has resources dependent on it. This will demonstrate how Docker handles such situations.

First, let's re-enable the vieux/sshfs plugin so we can use it.

docker plugin enable vieux/sshfs

Now, let's create a Docker volume that uses the vieux/sshfs plugin. This will create a dependency on the plugin.

docker volume create --driver vieux/sshfs -o sshcmd=user@host:/path/to/dir -o IdentityFile=~/.ssh/id_rsa sshfs_volume

Note: This command will likely fail because you don't have a valid SSH host and key configured. This is expected and serves the purpose of creating a volume that attempts to use the plugin, thus creating a reference. You will see an error message indicating that the volume creation failed.

Now, let's try to disable the vieux/sshfs plugin again while the volume sshfs_volume exists, even though the volume creation failed.

docker plugin disable vieux/sshfs

You should see an error message similar to this:

Error response from daemon: plugin vieux/sshfs is in use by volume sshfs_volume

This error occurs because Docker prevents you from disabling a plugin that is currently referenced by other Docker resources, such as volumes. This is a safety mechanism to prevent unexpected behavior or data loss.

To successfully disable the plugin in this scenario, you would first need to remove the dependent resource (the volume in this case). Let's remove the volume:

docker volume rm sshfs_volume

Now, you should be able to disable the plugin:

docker plugin disable vieux/sshfs

This time, the command should succeed without an error message.

This step illustrates that Docker manages dependencies and prevents you from disabling plugins that are actively being used.

Force disable an active plugin (optional)

In this optional step, you will learn how to force disable a Docker plugin. This is sometimes necessary when a plugin is stuck or cannot be disabled normally. However, use the force option with caution, as it can potentially lead to unexpected behavior if the plugin is actively being used by critical resources.

First, let's ensure the vieux/sshfs plugin is enabled.

docker plugin enable vieux/sshfs

Now, let's try to force disable the plugin using the -f or --force flag:

docker plugin disable -f vieux/sshfs

Even with the force flag, if the plugin is actively being used by a running container or other critical resource, Docker might still prevent the disable operation to avoid system instability. However, for a simple plugin like vieux/sshfs that is not actively managing a running container, the force flag will typically succeed even if there were lingering references (though we removed the volume reference in the previous step).

The force option is primarily designed to handle situations where a plugin is unresponsive or cannot be disabled through the standard method. It attempts to shut down the plugin process and disable it regardless of its current state or minor references.

After attempting to force disable, you can verify the plugin's status:

docker plugin ls

The vieux/sshfs plugin should now be listed with ENABLED set to false.

ID                  NAME                DESCRIPTION                         ENABLED
<plugin_id>         vieux/sshfs         Mount remote SSH filesystem         false

This concludes the optional steps on handling plugin dependencies and force disabling. You have learned how to list, disable, and verify the status of Docker plugins, as well as how Docker handles attempts to disable plugins with references.

Summary

In this lab, you learned how to manage Docker plugins, specifically focusing on disabling them. You began by listing installed plugins using docker plugin ls to understand their status and identify which ones are active. You then practiced disabling a plugin using the docker plugin disable command, demonstrating how to stop a plugin's functionality. Finally, you verified that the plugin was successfully disabled.