How can multiple custom plugins be configured for Kong when using Docker?
How to deploy multiple custom plugins in Kong in Docker
How do I deploy multiple custom plugins in Kong running in Docker?
Mount your custom plugins to a path outside the standard Kong plugins directory, then point KONG_LUA_PACKAGE_PATH at it (e.g. /usr/local/custom_plugins/?.lua;;) and list the plugins in KONG_PLUGINS alongside bundled.
Restart the container to pick up code changes.
Steps
Implementing and updating custom plugins in Kong, particularly within a Docker environment, requires careful consideration of volume mounts and the lua_package_path configuration to avoid overwriting existing plugins and to enable seamless updates. Here’s a step-by-step guide based on a successful resolution:
-
Mount custom plugin code to a Docker volume.
To avoid overwriting the standard Kong plugins directory and ensure that your custom plugins are correctly recognized, you should mount your custom plugins directory outside the standard Kong plugins directory.
First, organize your custom plugins on your host machine with the correct directory structure. For example, if you have custom plugins named
log-filterandcustom-handler, your directory structure should look like this:custom_plugins/ ├─ kong/ └─── plugins/ ├───── log-filter/ └───── custom-handler/Then, mount this directory to the container using a Docker volume that points outside the standard Kong plugins directory:
-v /path/to/custom_plugins:/usr/local/custom_plugins -
Configure
lua_package_path.Adjust the
lua_package_pathto include your custom plugins directory. This tells Kong where to find your custom plugins without interfering with the default plugin directory.-e "KONG_LUA_PACKAGE_PATH=/usr/local/custom_plugins/?.lua;;"The
?in thelua_package_pathis expanded tokong/plugins/<plugin-name>. So for our example plugins, the path will be expanded to:/usr/local/custom_plugins/kong/plugins/<plugin-name>where
<plugin-name>will be eitherlog-filterorcustom-handler. -
Load custom plugins.
Specify your custom plugins in the
KONG_PLUGINSenvironment variable, along with the bundled plugins, to ensure they are loaded by Kong.-e "KONG_PLUGINS=bundled, log-filter, custom-handler" -
Update custom plugins or add new ones.
Updating the plugin code on the host requires restarting the Kong container to reflect the changes. For adding new plugins, simply follow the steps above to include them in your custom plugins directory and update the
KONG_PLUGINSenvironment variable accordingly.