gpt4 book ai didi

Docker TICK Sandbox 不提供 UDF Python 功能

转载 作者:行者123 更新时间:2023-12-02 18:29:40 25 4
gpt4 key购买 nike

我正在运行 this docker 镜像以在本地使用 TICK Kapacitor。

我面临的问题是,当我尝试使用用户定义函数时,例如 these examples 中的任何一个我收到/usr/bin/python2 不存在的错误消息。

我将以下内容添加到 kapacitor.conf :

[udf.functions]
[udf.functions.tTest]
prog = "/usr/bin/python2"
args = ["-u", "/tmp/kapacitor_udf/mirror.py"]
timeout = "10s"
[udf.functions.tTest.env]
PYTHONPATH = "/tmp/kapacitor_udf/kapacitor/udf/agent/py"

我方面的进一步尝试包括更改用于构建 Kapacitor 以安装 python 的图像,但代理似乎无论如何都无法编译。

有没有人设法让 UDF 使用 Kapacitor Docker 镜像运行?

谢谢

最佳答案

来自官方仓库的 Docker 镜像:docker pull kapacitor里面没有安装python。您可以通过在容器中运行 shell 来验证这一点:

PS> docker exec -it kapacitor bash

并执行命令选项之一:
$ python -VERSION 
$ python: command not found

或者
$ readlink -f $(which python) | xargs -I% sh -c 'echo -n "%:"; % -V'
$ readlink: missing operand

或者
$ find / -type f -executable -iname 'python *'

无效返回。相反,如果 python 可用,命令返回版本和可执行文件列表

Note: Here and further all command snippets are given for Powershell on Windows. And all command snippets inside docker container are given for bash shell as Linux images are used.



基本上,有两个选项可以使用里面的 python 获取 kapacitor 图像来执行 UDF:
  • kapacitor 中安装 python镜像,即从非常 kapacitor 构建新的 docker 镜像图片。
    可以找到示例 here :
  • 构建 kapacitor 的新版本来自 python 官方图像之一的图像

    第二个选项更自然,因为您可以获得一致的 python 安装并继续努力安装 docker 社区已经完成的 python 安装工作。

  • 因此,按照选项 2,我们将执行:
  • 查看官方kapacitor的Dockefile图片
  • 选择合适的python图片
  • 为 kapacitor
  • 创建新项目和 Dockerfile
  • 构建并检查 kapacitor 镜像


  • 检查官方kapacitor图像的Dockefile

    一般说明:

    For any image, the original Dockerfiles can be obtained in this way:

    https://hub.docker.com/ -> Description Tab -> Supported tags and respective Dockerfile links section -> each of the tags is a link that leads to the Dockerfile



    所以对于 kapacitor,一切都在 influxdata-docker git repository

    然后在 Dockerfile我们发现图像是基于
    FROM buildpack-deps: stretch-curl

    这里:

    buildpack-deps

    the image provided by the project of the same name https://hub.docker.com/_/buildpack-deps

    curl

    This variant includes just the curl, wget, and ca-certificates packages. This is perfect for cases like the Java JRE, where downloading JARs is very common and   necessary, but checking out code isn't.

    stretch

    short version name of the OS, in this case Debian 9 stretch https://www.debian.org/News/2017/20170617


    Buildpack-deps图像又是基于
    FROM debian: stretch

    Debian images从最小的 docker 图像
    FROM: scratch

    选择合适的python图像

    在python图像中,例如 3.7 ,你 can find similar versions inheriting from buildpack-deps
    FROM buildpack-deps: stretch

    在继承之后,我们将看到:
    FROM buildpack-deps: stretch
    FROM buildpack-deps: stretch-smc
    FROM buildpack-deps: stretch-curl
    FROM debian: stretch

    换句话说, python: 3.7-stretchkapacitor 相比,图像仅向 Debian 添加了功能。图片。
    这意味着我们可以重建 kapacitor python image: 3.7-stretch 顶部的图像没有风险或获得不兼容。

    Docker 上下文文件夹准备
  • 克隆存储库
    https://github.com/influxdata/influxdata-docker.git
  • 创建文件夹influxdata-docker/kapacitor/1.5/udf_python/python3.7
  • 将以下三个文件从influxdata-docker/kapacitor/1.5/复制进去:

    Dockerfile
    入口点.sh
    kapacitor.conf
  • 在复制的 Dockerfile FROM buildpack-deps: stretch-curl替换为 FROM python: 3.7-stretch
  • 小心! 如果我们在 Windows 上工作并且出于科学好奇心打开 entrypoint.sh项目文件夹中的文件,然后确保检查它不会将结束行字符从 Linux (LF) 更改为 Windows 变体:(CR LF)。
    否则,稍后启动容器时,会出现错误:
  • 或在容器日志中:
    exec: bad interpreter: No such file or directory
  • 或者,如果您将开始调试并使用 bash 运行容器,将执行以下操作:
    $ root @ d4022ac550d4: / # exec /entrypoint_.sh
    $ bash: /entrypoint_.sh: / bin / bash ^ M: bad interpreter: No such file or directory


  • build

    运行 PS> docker build -f. \ Dockerfile -t kapacitor_python_udf

    Again, in case of Windows environment

    If during the build execution an error occurs of the form:

      E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 9h 14min 10s). Updates for this repository will not be applied.

    then your computer clock probably went out of sync and/or Docker Desktop incorrectly initialized the time after the system returned from sleep. See the issue)

    To fix it, restart Docker Desktop and / or Windows settings -> Date and time settings -> Clock synchronization -> perform Sync

    You can also read more here



    启动并检查

    使用与标准镜像相同的操作启动容器。例子:
    PS> docker run --name=kapacitor -d `
    --net=influxdb-network `
    -h kapacitor `
    -p 9092:9092 `
    -e KAPACITOR_INFLUXDB_0_URLS_0=http://influxdb:8086 `
    -v ${PWD}:/var/lib/kapacitor `
    -v ${PWD}/kapacitor.conf:/etc/kapacitor/kapacitor.conf:ro `
    kapacitor

    查看:
    PS> docker exec -it kapacitor_2 bash

    $ python -VERSION
    $ Python 3.7.7

    $ readlink -f $(which python) | xargs -I% sh -c 'echo -n "%:"; % -V'
    $ /usr/local/bin/python3.7: Python 3.7.7

    关于Docker TICK Sandbox 不提供 UDF Python 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51142238/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com