Docker Kong-自定义插件返回:自定义插件已启用但未安装;
我有一个使用Dockerfile运行的Kong实例,其内容如下:Docker Kong-自定义插件返回:自定义插件已启用但未安装;,docker,dockerfile,kong,Docker,Dockerfile,Kong,我有一个使用Dockerfile运行的Kong实例,其内容如下: FROM kong:1.4.0 WORKDIR /files COPY plugins kong/plugins ENV KONG_LOG_LEVEL=debug ENV KONG_PLUGINS custom-plugin ENV KONG_LUA_PACKAGE_PATH /files/?.lua;; 但是,在docker运行时,返回 error loading plugin schemas: on plugin 'cus
FROM kong:1.4.0
WORKDIR /files
COPY plugins kong/plugins
ENV KONG_LOG_LEVEL=debug
ENV KONG_PLUGINS custom-plugin
ENV KONG_LUA_PACKAGE_PATH /files/?.lua;;
但是,在docker运行时,返回
error loading plugin schemas: on plugin 'custom-plugin': custom-plugin plugin is enabled but not installed;
module 'kong.plugins.custom-plugin.handler' not found:No LuaRocks module found for kong.plugins.custom-plugin
我已经确认文件的结构正确,运行时嵌套在kong/plugins目录中
有人能帮助解决这个问题吗?看看来自(另一个依赖于
kong.plugins.custom plugin.handler
的插件)的指令之一是否适用于kong.plugins.custom plugin.handler
本身
其要点是,该插件应该可以在磁盘上供Kong使用,并添加到自定义插件配置属性中
您可以通过多种方式实现这一点:
- 使用Docker卷
- 创造自己的形象
- 或者甚至与项目或灵感,如李>
-e Kong\u CUSTOM\u PLUGINS=my CUSTOM plugin
也可以
插件还需要位于LUA\u路径中(类似于路径,但适用于LUA模块)
因此,简而言之,可能的解决方案之一是使用卷和环境变量:
- 挂载插件代码:
-v/path/to/my-custom-plugin:/etc/kong/plugins/my-custom-plugin
- 将包含自定义插件的目录添加到
LUA\u路径
:-e KONG\u LUA\u PACKAGE\u路径=/etc/?.LUA
(KONG需要KONG.plugins.custom plugin.handler
,翻译为/etc/KONG/plugins/my custom plugin/handler.LUA
)
- 指示Kong加载带有以下内容的插件:
-e Kong\u CUSTOM\u PLUGINS=my CUSTOM plugin
接下来,首先检查这是否是一个KONG\u LUA\u路径问题,如中所示
这是关于插件迁移的,但在这里可能也有影响
作为短期解决方案,您应该将LUA_PATH
环境变量设置为指向自定义插件的安装路径
(而不是kong.conf
或kong\u lua\u package\u path
中的lua\u package\u path
)
例如,我刚搬家:
export KONG_LUA_PACKAGE_PATH="/path/to/some-custom-plugin/?.lua;;"
致:
export LUA_PATH="/path/to/some-custom-plugin/?.lua;$LUA_PATH"
并再次运行了kong migrations up
,成功地运行了插件的迁移
这是因为lua\u package\u path
仅用于运行时Kong(在nginx中),CLI不考虑它(使用Kong migrations
命令)
如果我只是在kong.conf
中注释了lua\u包路径
,并如您所述导出了lua\u路径
,它开始给我这个错误:
./kong:3: module 'luarocks.loader' not found:
我执行kong向上迁移的shell以前从未设置过LUA\u路径
set。如果尚未在shell中设置,则会出现luarocks
内部创建LUA\u路径
因此,我必须执行的另一个步骤是通过运行“luarockspath
”命令获取当前的LUA_路径
”,然后获取该路径的结果,并将自定义登录插件路径附加到该路径,然后导出LUA_路径
,以使其正常工作
同样,即使您当前的问题与迁移无关,其中一个变量可能会有所帮助。请查看以下参考资料:
来自香港的错误报告:
更新
您需要安装lua包管理器luarocks
谢谢您的回答。我尝试按上述方式运行解决方案,但luarocks make
行抛出:缺少参数:请指定要在当前目录上使用的rockspec。我在plugins/custom plugin目录下运行它,我也在custom plugin目录下尝试过,但是我得到了相同的错误。您需要安装lua包管理器luarock
:|答案已更新,请参阅答案的结尾。
I don't think it's the luarocks' problem
Indeed, I installed kong in docker whose image is built by a dockerfile.
In my docker file, I went into the folder which store the custom plugins,and then traverse and luarocks make them by shell.It looks like:
#install private plugins
cd APIGPlugins
for dir in `ls`; do
if [ -d $dir ]; then
cd $dir;
luarocks make;
cd ../;
fi
done
and then, I run the docker images for a container by the directive:
sudo docker run -d --name kong \
-e "KONG_DATABASE=off" \
-e "KONG_DECLARATIVE_CONFIG=/etc/kong/kong.yml" \
-e "KONG_PLUGINS=apig-response-transform" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong-plugin:v4
As u see, I set the kong plugin by the docker run env variable parameter for enable the plugin instead of setting in the kong.conf.
The logs were generated by directive of docker logs "container ID"
It works when I tried to install another custom plugin in this way,but not work when install the custom plugin I described before