0

I want to run a docker container of RYU controller in cloudify ways. I have written a blueprint file with which I can create relevant deployment and finally start the docker container.

The problem is, the controller (within the docker container) needs to implement a script to function but I don't know how to modify the blueprint file for automatically running the script. Every time, I have to type docker exec CONTAINER ryu-manager /path/simple_switch.py for the goal.

So does anyone know where the command should be put in the blueprint. I tried to include it in

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 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ 

but received an error of unexpected parameter.

Thanks for your time and any opinions would be appreciated~


Or let me put in this way, if anyone knows, which part in the cloudify blueprint matches docker exec?

Lootii
  • 3
  • 3

2 Answers2

1

I use Cloudify a lot and I use Docker a lot. The Docker Plugin is kind of "nice to have", but it is really not necessary. You can just run commands like "docker exec" and "docker run" from inside of the the Cloudify Script plugin and get the same result, and you do not need to figure out a different interface for working with Docker.

For example if I have this cloudify blueprint (simplified):

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

I can call such scripts:

scripts/create.sh:

docker run -d ryu

scripts/start.sh

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

earthmant
  • 259
  • 1
  • 4
  • Wow! This sounds cool and simple enough! I thought using the official plugin was a must. Thanks a lot! I'll take a try. – Lootii Jul 31 '17 at 01:14
  • It works fine the way you came up with! But the flags may be out of the question. The container fails to keep running by `run -d` and `-t` leads to `the input device is not a tty` error. Anyway, the solution is really of great help. Thanks again! – Lootii Jul 31 '17 at 12:29
  • Hi, @earthmant ! Can I ask one more question? Since a docker container is run by a script, am I right that the state of container is simply an outcome of script? That's to say, the container actually has nothing to do with any cloudify node. ( I found myself cannot influence containers by other means ...) – Lootii Dec 13 '17 at 12:58
  • There is not really any state verification in this way of handling the container, correct. Maybe look into using the Cloudify Kubernetes Plugin and package the application as a Pod? – earthmant Jan 07 '18 at 13:09
0

Before I answer, I have no experience in cloudify, but I have looked at the documentation to see what is it all about. Here are my pointers to you.

First of all I looked at the docker plugin at below URL

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

And it doesn't have any execute statement as such. So you should remove the command from both your create and start lifecycles. Doing that would make sure the default image command runs.

Now your task is to execute an additional command inside the container. Since the docker plugin doesn't support that operation, your best bet is to get the container ID of the newly created container. This should be possible using some output parameter capturing

Now you want to execute a command on your local machine or the remote machine where docker is installed. This you can setup as another lifecycle which takes the ID from the created container and executes the docker exec <ID> ryu-manager /ryu/ryu/app/simple_switch.py command on that main docker host

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • Thanks, Tarun, for your special efforts in the answer! I recommend [this docker plugin](https://github.com/docker/docker-py/blob/master/docker/api/container.py), which consists of more (no `command` in `start` of course ). – Lootii Jul 26 '17 at 07:34
  • I tried to add a `run` lifecycle. Since the [docker plugin](http://docs.getcloudify.org/4.0.0/plugins/docker/#create) seems to only support `create`,`start`,`stop` and `remove_container`, I consider no new change is reasonable. – Lootii Jul 26 '17 at 07:39