首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在docker中使用声明性配置的自定义插件配置

在docker中使用声明性配置的自定义插件配置
EN

Stack Overflow用户
提问于 2020-10-01 20:06:34
回答 1查看 1.2K关注 0票数 0

我在声明模式中使用docker中的kong。

我想从这里尝试一下插件kong-jwt2header:https://docs.konghq.com/hub/yesinteractive/kong-jwt2header/

我按照kong.yml中的描述对其进行了配置:

代码语言:javascript
复制
plugins:
- name: kong-jwt2header
  config: 
    strip_claims: false
    token_required: true

我将一个插件文件夹链接到docker容器中:

代码语言:javascript
复制
version: '3'
services:

  kong:
    container_name: kong
    image: kong:2.1.3-centos
    environment:
      - KONG_DATABASE=off
      - KONG_DECLARATIVE_CONFIG=/usr/local/kong/declarative/kong.yml
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_CUSTOM_PLUGINS=kong-jwt2header
      - KONG_ADMIN_LISTEN=0.0.0.0:7001, 0.0.0.0:7444 ssl
      - KONG_LOG_LEVEL=${KONG_LOG_LEVEL:-info}
    volumes:
      - ./kong.yml:/usr/local/kong/declarative/kong.yml
      - ./plugins:/usr/local/kong/plugins
    ports:
      - 7000:8000
      - 7001:7001
      - 7443:8443
      - 7444:7444

在启动时,我得到了一个异常,需要启用插件。

代码语言:javascript
复制
2020/10/01 11:45:08 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:491: error parsing declarative config file /usr/local/kong/declarative/kong.yml:
in 'services':
  - in entry 2 of 'services':
    in 'plugins':
      - in entry 1 of 'plugins':
        in 'name': plugin 'kong-jwt2header' not enabled; add it to the 'plugins' configuration property
stack traceback:
        [C]: in function 'error'
        /usr/local/share/lua/5.1/kong/init.lua:491: in function 'init'
        init_by_lua:3: in main chunk
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:491: error parsing declarative config file /usr/local/kong/declarative/kong.yml:
in 'services':
  - in entry 2 of 'services':
    in 'plugins':
      - in entry 1 of 'plugins':
        in 'name': plugin 'kong-jwt2header' not enabled; add it to the 'plugins' configuration property
stack traceback:
        [C]: in function 'error'
        /usr/local/share/lua/5.1/kong/init.lua:491: in function 'init'
        init_by_lua:3: in main chunk

在互联网上搜索时,我发现了这个:https://github.com/Kong/docker-kong/issues/227

他们写道,我必须将其添加到kong.conf文件的//plugins//变量中,就像插件开发指南中所描述的那样。(https://docs.konghq.com/1.1.x/plugin-development/distribution/#load-the-plugin)

我试着把它设置在docker-compose中

代码语言:javascript
复制
     - KONG_CUSTOM_PLUGINS=kong-jwt2header

没有成功。

我在docker_compose.yml中设置了环境变量

代码语言:javascript
复制
     - KONG_PLUGINS=bundled,kong-jwt2header

现在我得到了一个新的异常,它表明插件kong-jwt2header已启用,但尚未安装。

我在/etc/kong/中找到了容器内部的kong.conf.defaults,并将其复制到外部,添加了属性插件,如docker指南中所述,并将其挂载到容器中。

现在我得到了这个异常:

代码语言:javascript
复制
2020/10/01 12:33:09 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:484: error loading plugin schemas: on plugin 'kong-jwt2header': kong-jwt2header plugin is enabled but not installed;
module 'kong.plugins.kong-jwt2header.handler' not found:No LuaRocks module found for kong.plugins.kong-jwt2header.handler
        no field package.preload['kong.plugins.kong-jwt2header.handler']

现在我再也没有想法了。(在没有docker和声明性方法的情况下尝试)

如何使用声明性配置将自定义插件添加到docker容器内?

EN

回答 1

Stack Overflow用户

发布于 2020-11-16 06:46:18

你需要在容器内安装带有luarock的插件。

代码语言:javascript
复制
USER root
RUN apk update && apk add git unzip luarocks
RUN luarocks install kong-oidc  
USER kong

如果您使用基于阿尔卑斯的kong-latest,则可以使用该示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64155056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档