How to use docker plugin set command to change plugin settings

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to use the docker plugin set command to modify the settings of a Docker plugin. We will begin by inspecting the initial configuration of a plugin using docker plugin inspect to understand its current state.

Following the inspection, you will practice changing various plugin settings, including environment variables, the source of a mount, a device path, and the source of arguments, all using the docker plugin set command. This hands-on experience will demonstrate the flexibility and control you have over Docker plugin behavior.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker/ContainerOperationsGroup -.-> docker/ls("List Containers") docker/ContainerOperationsGroup -.-> docker/inspect("Inspect Container") subgraph Lab Skills docker/ls -.-> lab-555195{{"How to use docker plugin set command to change plugin settings"}} docker/inspect -.-> lab-555195{{"How to use docker plugin set command to change plugin settings"}} end

Inspect initial plugin settings

In this step, we will learn how to inspect the initial settings of a Docker plugin. Docker plugins extend the functionality of Docker, allowing for custom storage drivers, network drivers, and more. Before modifying a plugin's settings, it's crucial to understand its current configuration.

We will use the docker plugin inspect command to view the details of a specific plugin. For this lab, we will use the vieux/sshfs plugin as an example. This plugin allows you to mount remote SSH file systems into your containers.

First, let's make sure the vieux/sshfs plugin is installed and enabled. If it's not, you can install it using the docker plugin install command.

docker plugin install vieux/sshfs:latest

This command installs the vieux/sshfs plugin from Docker Hub. The :latest tag specifies the latest version of the plugin.

After the plugin is installed, you can verify its status using the docker plugin ls command.

docker plugin ls

You should see vieux/sshfs:latest listed with the ENABLED status set to true.

Now, let's inspect the plugin's settings using the docker plugin inspect command.

docker plugin inspect vieux/sshfs:latest

This command will output a detailed JSON object containing all the configuration details of the vieux/sshfs plugin. This output includes information about the plugin's ID, name, enabled status, settings, and more.

Scroll through the output to see the various configuration options available for this plugin. Pay attention to the Settings section, which contains the specific configuration parameters that can be modified.

Change an environment variable using docker plugin set

In this step, we will learn how to change an environment variable for a Docker plugin using the docker plugin set command. Modifying plugin settings allows you to customize their behavior to fit your specific needs.

Before we can change a plugin's settings, the plugin must be disabled. You cannot change the settings of an enabled plugin. We will continue to use the vieux/sshfs plugin as our example.

First, let's disable the vieux/sshfs plugin.

docker plugin disable vieux/sshfs:latest

This command disables the specified plugin. You can verify that the plugin is disabled by running docker plugin ls again. The ENABLED status for vieux/sshfs:latest should now be false.

Now that the plugin is disabled, we can change an environment variable. The vieux/sshfs plugin has an environment variable called DEBUG which controls debugging output. By default, this is likely set to false. Let's change it to true.

docker plugin set vieux/sshfs:latest DEBUG=true

This command sets the DEBUG environment variable for the vieux/sshfs:latest plugin to true. The format for setting variables is PLUGIN_NAME VARIABLE_NAME=VALUE.

After setting the environment variable, you can inspect the plugin again to confirm the change.

docker plugin inspect vieux/sshfs:latest

Look for the Settings section in the JSON output. You should see an entry for Env which is a list of environment variables. The DEBUG variable should now be set to true.

Finally, after making the desired changes, you can re-enable the plugin.

docker plugin enable vieux/sshfs:latest

Verify that the plugin is enabled using docker plugin ls.

Change the source of a mount using docker plugin set

In this step, we will learn how to change the source of a mount for a Docker plugin using the docker plugin set command. Some plugins require access to specific directories or files on the host system. These are configured as mounts.

Similar to changing environment variables, you must disable the plugin before you can modify its mount settings. We will continue using the vieux/sshfs plugin.

First, ensure the vieux/sshfs plugin is disabled. If you enabled it in the previous step, disable it now.

docker plugin disable vieux/sshfs:latest

Verify the plugin is disabled using docker plugin ls.

The vieux/sshfs plugin requires access to the /etc/ssh/ssh_known_hosts file on the host system to verify the identity of the SSH server it connects to. This is configured as a mount. Let's change the source path of this mount.

We will change the source path from /etc/ssh/ssh_known_hosts to /root/.ssh/known_hosts. Note: In a real-world scenario, you would ensure the target file exists and has the correct permissions. For this lab, we are focusing on the command syntax.

docker plugin set vieux/sshfs:latest Mounts[0].Source=/root/.ssh/known_hosts

This command sets the Source field of the first mount (Mounts[0]) for the vieux/sshfs:latest plugin to /root/.ssh/known_hosts. The syntax Mounts[0] refers to the first element in the Mounts array within the plugin's settings. You can find the index of the mount you want to change by inspecting the plugin's configuration.

After changing the mount source, inspect the plugin to confirm the change.

docker plugin inspect vieux/sshfs:latest

Examine the Settings section and find the Mounts array. The Source field for the first mount should now be /root/.ssh/known_hosts.

Finally, re-enable the plugin.

docker plugin enable vieux/sshfs:latest

Verify that the plugin is enabled using docker plugin ls.

Change a device path using docker plugin set

In this step, we will learn how to change the path of a device that a Docker plugin has access to using the docker plugin set command. Some plugins might require direct access to host devices, such as storage devices or network interfaces.

As with changing other plugin settings, the plugin must be disabled before you can modify its device configurations. We will continue using the vieux/sshfs plugin as our example, although this specific plugin doesn't typically require device access. We will demonstrate the command syntax using a hypothetical device.

First, ensure the vieux/sshfs plugin is disabled.

docker plugin disable vieux/sshfs:latest

Verify the plugin is disabled using docker plugin ls.

Now, let's imagine the vieux/sshfs plugin had a requirement to access a device at /dev/sda1. We want to change this to /dev/sdb1. We would use the docker plugin set command with the Devices array.

Note: The vieux/sshfs plugin does not actually have a Devices configuration by default. This is a hypothetical example to demonstrate the command syntax for changing device paths. Running this command on the vieux/sshfs plugin will likely result in an error because the Devices field does not exist in its configuration. However, the syntax shown is correct for plugins that do have device configurations.

Assuming the plugin had a Devices array and we wanted to change the PathOnHost of the first device (Devices[0]), the command would look like this:

docker plugin set vieux/sshfs:latest Devices[0].PathOnHost=/dev/sdb1

This command attempts to set the PathOnHost field of the first device (Devices[0]) for the vieux/sshfs:latest plugin to /dev/sdb1. The syntax Devices[0] refers to the first element in the Devices array within the plugin's settings.

Since the vieux/sshfs plugin doesn't have a Devices array, the command above will fail. This is expected for this specific plugin, but it illustrates the correct syntax for modifying device paths for plugins that support this configuration.

To see the actual settings of the vieux/sshfs plugin, you can inspect it again.

docker plugin inspect vieux/sshfs:latest

You will not see a Devices section in the output for this plugin.

Finally, re-enable the plugin.

docker plugin enable vieux/sshfs:latest

Verify that the plugin is enabled using docker plugin ls.

Change the source of the arguments using docker plugin set

In this step, we will learn how to change the source of the arguments passed to a Docker plugin using the docker plugin set command. Some plugins accept command-line arguments during their initialization or execution.

To modify the arguments of a plugin, it must be disabled first. We will continue using the vieux/sshfs plugin as our example.

First, ensure the vieux/sshfs plugin is disabled.

docker plugin disable vieux/sshfs:latest

Verify the plugin is disabled using docker plugin ls.

The vieux/sshfs plugin accepts arguments that are passed to the underlying sshfs command. These arguments are configured in the plugin's settings. Let's change the source of these arguments.

We will change the source of the arguments to include the -o allow_other option, which allows non-root users to mount the file system.

docker plugin set vieux/sshfs:latest Args="-o allow_other"

This command sets the Args field for the vieux/sshfs:latest plugin to "-o allow_other". The Args field is typically a string or an array of strings that represent the command-line arguments passed to the plugin's executable.

After changing the arguments, inspect the plugin to confirm the change.

docker plugin inspect vieux/sshfs:latest

Examine the Settings section and find the Args field. It should now be set to "-o allow_other".

Finally, re-enable the plugin.

docker plugin enable vieux/sshfs:latest

Verify that the plugin is enabled using docker plugin ls.

Summary

In this lab, we learned how to manage Docker plugin settings using the docker plugin set command. We began by inspecting the initial configuration of a plugin using docker plugin inspect to understand its current state, specifically focusing on the Settings section. This initial inspection is crucial before making any modifications.

Subsequently, we explored how to modify various plugin settings using docker plugin set. We covered changing an environment variable, altering the source of a mount, modifying a device path, and changing the source of arguments. These steps demonstrated the flexibility of docker plugin set in customizing plugin behavior to meet specific requirements.