mcuadros/ofelia

Run a NEW command in a stopped container with `job-run`?

andburch opened this issue · 1 comments

I am trying to get a (R) script to run ONLY when it is run by ofelia. In the docker-compose.yml file, I have this container's initial command just echo the phrase "started and stopped" before exiting. But I want ofelia to run a script using this container every minute. However, whenever I have ofelia run the container using job-run, the initial command is run, NOT the command I specify with ofelia.

    rscript:
        restart: "no"
        labels:
            ofelia.enabled: "true"
        image: 'my/rscripts:4'
        command:
            - echo
            - "started and stopped"

    ofelia:
        image: mcuadros/ofelia:latest
        depends_on:
            - rscript
        command: daemon --docker
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock:ro
        labels:
            ofelia.enabled: "true"
            ofelia.job-run.EZupdate.schedule: "@every 60s"
            ofelia.job-run.EZupdate.command: "Rscript /home/rstudio/scripts/myscript.R"
            ofelia.job-run.EZupdate.container: "dockertest-rEZ-1"

However, the container just echoes "started and stopped" every sixty seconds, it never actually runs the script.

How can I have ofelia run a different command in this container, rather than what the container runs at startup?

Ah, I just figured out the situation, in case anyone else has a similar question.

Although it's not specifically mentioned, the (1) and (2) next to the parameters of job-run documentation as shown below:

... Schedule * (1,2) ...

are used to indicate which of the job-run situations they apply to. (1) is the docker run scenario and (2) is the docker start scenario.

You can apparently only use the command parameter in the first scenario, not when restarting an exited container. I think it might make sense to split job-run into two functions to make these distinctions clearer, but ah well.