如何将 lua-cjson 添加到我的 nginx lua 容器中?

我正在使用这个 docker-compose 创建支持 Lua 的 Nginx:

version: '3.9'
services:
  nginx:
    container_name: local_nginx
    image: fabiocicerchia/nginx-lua

    environment:
      - REDIS_SERVER=172.26.0.1
    ports:
      - 8089:80
      - 8053:8053
    volumes:
      - /home/navid/lua_project/nginx/nginx.conf:/etc/nginx/nginx.conf
      - /home/navid/lua_project/nginx/www:/usr/share/nginx/html
      - /home/navid/lua_project/lib/resty/redis.lua:/usr/local/share/luajit-2.0.4/resty/redis.lua
      - /home/navid/lua_project/lib/resty/kafka:/usr/local/share/lua/5.1/resty/kafka

    extra_hosts:
      - host.docker.internal:host-gateway

现在我需要在我的容器中添加 cjson 库。我在我的主机上尝试使用构建方法,但是它抛出这个异常:

lua.h: No such file or directory

我还添加了这些行来使其在我的容器上运行:

- /home/navid/lua_project/lib/resty/lua-cjson:/usr/local/share/lua/5.1/resty/cjson

        command:
          - |
            cd /usr/local/share/lua/5.1/resty/cjson
            autoreconf -i -v --force
            ./configure
            make
            make install

但是在运行阶段失败并显示了这个错误:

exec: line 38: cd /usr/local/share/lua/5.1/resty/cjson autoreconf -i -v --force ./configure make make install : not found

是否有任何直接方法在我的容器中安装 cjson?

更新:

最终我已经构建并上传了 cjson.so 到我的 Docker 容器中,但是我得到了这个错误:

loading module 'cjson' from file '/usr/local/lib/lua/5.1/cjson.so': Error relocating /usr/local/lib/lua/5.1/cjson.so: __snprintf_chk:找不到符号

是否有其他性能良好的替代库?

点赞
用户4984564
用户4984564

看起来您正在尝试在标准的 nginx 安装中使用 openresty 模块,这不可行,因为它们不是同一件事情。Openresty 本质上是 nginx + LuaJIT。

2021-05-10 08:38:38
用户888162
用户888162

这可能是您问题的解决方法。

这是一个 Dockerfile,允许您使用cjson:

FROM fabiocicerchia/nginx-lua:1-alpine-compat

RUN apk add gcc musl-dev coreutils \
    && luarocks install lua-cjson

更多细节:https://github.com/fabiocicerchia/nginx-lua/issues/34

2021-12-20 13:44:04