如何编辑蓝图以通过 cloudify 在 docker 容器 运行 中自动 运行ning 命令

how to edit blueprint for automatically running a command in docker container run by cloudify

我想运行一个docker RYU控制器的容器以cloudify的方式。我已经编写了一个蓝图文件,我可以使用它来创建相关部署并最终启动 docker 容器。

问题是,控制器(在 docker 容器内)需要执行脚本才能运行,但我不知道如何修改蓝图文件以自动 运行ning 脚本.每次,我都必须输入 docker exec CONTAINER ryu-manager /path/simple_switch.py 作为目标。

那么有谁知道命令应该放在蓝图中的什么地方。我试图将其包含在

interfaces:
  cloudify.interfaces.lifecycle:
    create:
      implementation: docker.docker_plugin.tasks.create_container
      inputs:
        params:
          ports:
            - { get_input: docker_port }
          stdin_open: true
          tty: true
          command: /bin/bash

    start:
      implementation: docker.docker_plugin.tasks.start
      inputs:
        params:
          port_bindings: { get_input: container_port_binding }
          command: docker exec ryu ryu-manager /ryu/ryu/app/simple_switch.py
          # here ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ 

但收到意外参数错误。

感谢您的宝贵时间,如有任何意见,我们将不胜感激~


或者让我这样说,如果有人知道,cloudify 蓝图中的哪一部分匹配 docker exec

在我回答之前,我没有 cloudify 的经验,但我查看了文档以了解它的全部内容。这是我给你的建议。

首先我查看了下面的 docker 插件 URL

https://github.com/cloudify-cosmo/cloudify-docker-plugin/blob/master/docker_plugin/tasks.py

而且它本身没有任何执行语句。所以你应该从你的创建和开始生命周期中删除 command 。这样做将确保默认图像命令运行。

现在你的任务是在容器内执行一个额外的命令。由于 docker 插件不支持该操作,因此最好的办法是获取新创建的容器的容器 ID。这应该可以使用一些输出参数 capturing

现在您想在本地计算机或安装了 docker 的远程计算机上执行命令。您可以将其设置为另一个生命周期,它从创建的容器中获取 ID 并在该主 docker 主机

上执行 docker exec <ID> ryu-manager /ryu/ryu/app/simple_switch.py 命令

我经常使用 Cloudify,我也经常使用 Docker。 Docker 插件有点像 "nice to have",但确实没有必要。您可以从 Cloudify 脚本插件内部使用 运行 命令,例如 "docker exec" 和 "docker run",并获得相同的结果,并且您不需要找出不同的界面来使用 Docker.

例如,如果我有这个 cloudify 蓝图(简化版):

yaml node_templates: my_app: type: cloudify.nodes.SoftwareComponent interfaces: cloudify.interfaces.lifecycle: create: implementation: scripts/create.sh start: implementation: scripts/start.sh relationships: - type: cloudify.relationships.depends_on target: vm

我可以调用这样的脚本:

scripts/create.sh:

docker run -d ryu

scripts/start.sh

docker exec -it ryu ryu-manager /ryu/ryu/app/simple_switch.py