docker - 如何将自定义的 kong 插件添加到 dockerized kong 中

标签 docker dockerfile kong api-gateway

我有一个正在运行的 KONG 容器,我想向其中添加一个自定义插件,特别是 JWT crafter 。 我已经下载了该插件,但我不知道如何让它从我的 KONG 容器中启动。因此,如果有人处于相同的位置或知道任何可遵循的路线,这将非常有帮助。

最佳答案

我尝试做同样的事情,但尚未找到详细描述的答案。 您可以配置简单的 helloworld 插件,如下所示:( https://github.com/brndmg/kong-plugin-hello-world )

Docker 主机上的本地“插件”目录结构:

plugin directory structure

然后你可以挂载本地/plugins 目录并让 kong 从/plugins 目录加载自定义的 'helloworld' 插件

1)使用环境变量

$ docker run -d --name kong --network=kong-net \
-e "KONG_DATABASE=cassandra" \
-e "KONG_PG_HOST=kong-database" \ 
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
**-e "KONG_LUA_PACKAGE_PATH=/plugins/?.lua" \
-e "KONG_CUSTOM_PLUGINS=helloworld" \ ** 
...
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
**-v "/plugins:/plugins" \**
-p 8080:8000 -p 8443:8443 -p 8001:8001 -p 8444:8444 kong:latest

然后,您可以在 http://[kong-url]:8001/ 上看到配置的自定义插件

..
"custom_plugins": [
"helloworld"
],
..

2) 或者,您可以简单地安装描述您想要的插件的自定义 kong.conf 文件。

/etc/kong/kong.conf

plugins = bundled,helloworld,jwt-crafter

(似乎第二个选项对于最新版本的 Kong 更好,因为“kong_custom_plugin”配置打印“弃用”警告)

对于 JWT 工匠,https://github.com/foodora/kong-plugin-jwt-crafter 看来该插件维护得不好,导致使用 luarocks 安装失败并出现错误。

$ luarocks install kong-plugin-jwt-crafter
....
kong-plugin-jwt-crafter 1.0-0 depends on lua-resty-jwt ~> 0.1.10-1 (not installed)

Error: Could not satisfy dependency lua-resty-jwt ~> 0.1.10-1: No results matching query were found.

相反,您可以直接将 'resty-jwt' 添加到官方 docker 镜像中,以解决依赖关系,该依赖关系不包含在官方镜像中。并将“JWT crafter”复制到“/plugins”目录中,并加载。

(docker容器内)

 luarocks install lua-resty-jwt

希望这有帮助。

关于docker - 如何将自定义的 kong 插件添加到 dockerized kong 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50391213/

相关文章:

api-gateway - kong.conf 文件在哪里?

lua - 在 Lua 项目中管理开发依赖项的推荐方法是什么?

docker - Docker 中的 Kong : Configuring API endpoints without curl

Docker compose 端口映射,主机端口 != 容器端口

node.js - 无法访问 Vagrant Sync 文件夹内的文件

docker - Kubernetes部署数据库连接错误

r - 在 Google Cloud App Engine 上部署 Shiny 的应用程序会返回错误

php - 在Docker容器中使用php-fpm的ORA-28547

php - 如何在drupal容器中维护团队工作?

docker - 在Nginx配置中使用docker-compose服务名称