Topface / ansible-chronos_task

Deploy tasks on Chronos.
MIT License
3 stars 0 forks source link

Run job in docker container #1

Closed shakthimaan closed 9 years ago

shakthimaan commented 9 years ago

I have the following Ansible task running:


---
- name: Test
  hosts: mesos_master[0]
  gather_facts: yes

  roles:
    - role: chronos_task
      chronos_url: "http://{{ inventory_hostname }}:4400"
      chronos_tasks:
        - type: iso8601
          app:
            name: dockerjob
            owner: user@foo.com
            command: docker run hello-world:latest
            epsilon: PT30M
            retries: 1
            async: true
            schedule: R/2015-07-28T01:45:00.000Z/PT24H

This runs fine and exists in Chronos successfully. Is the command run on Chronos host or inside a Docker container?

How should the task be defined if a command need to be executing inside a Docker container? I have created the following JSON input:

{
 "schedule": "R\/2015-07-28T17:22:00Z\/PT2M",
 "name": "dockerjob",
 "container": {
  "type": "DOCKER",
  "image": "hello-world:latest"
 },
 "cpus": "0.1",
 "mem": "128",
 "uris": [],
 "command": "docker run hello-world:latest",
 "owner": "user@foo.com"
}

When I try to create the job in Chronos using curl:

curl -L -H 'Content-Type: application/json' -X POST -d "@/tmp/input.json" 10.0.137.160:4400/scheduler/iso8601

the job gets created, but, I see the following error in mesos-slave.ERROR when the job gets scheduled to run:

Error response from daemon: Cannot start container f422c5f503152c392a92cb5aca9425b2842e371b937b2d4a25817d7d94b3fb24: [8] System error: exec: "/bin/sh": stat /bin/sh: no such file or directory

What could I be missing?

bobrik commented 9 years ago

The task is run with mesos containerizer that runs docker. You can read about running docker containers here: http://mesos.github.io/chronos/docs/api.html#adding-a-docker-job.

I used to run docker with "command": "docker run --rm ..."

shakthimaan commented 9 years ago

I got it working using the following:

---
- name: Test
  hosts: mesos_master[0]
  gather_facts: yes

  roles:
    - role: chronos_task
      chronos_url: "http://{{ inventory_hostname }}:4400"
      chronos_tasks:
        - type: iso8601
          app:
            name: dockerjob
            owner: user@foo.com
            container:
              type: DOCKER
              image: libmesos/ubuntu
            command: for i in 1 2 3 4 5; do date; sleep 1; done
            epsilon: PT30M
            retries: 1
            async: true
            schedule: R/2015-07-29T17:20:00.000Z/PT24H