Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler not discovering docker-compose container based on labels

Open
ashleysommer opened this issue Nov 19, 2019 · 7 comments
Open

Comments

@ashleysommer
Copy link
Contributor

ashleysommer commented Nov 19, 2019

Here's my minimal reproduction of the docker-compose file:

version: "3"
services:

  scheduler:
    image: mcuadros/ofelia
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      ofelia.job-local.my-test-job.schedule: "@daily"
      ofelia.job-local.my-test-job.command: "echo 'still running'"
    command: ["daemon", "--docker"]

  test_schedule:
    image: alpine:3.9
    command: ["tail", "-f", "/dev/null"]
    depends_on:
      - scheduler
    labels:
      ofelia.enabled: "true"
      ofelia.job-exec.test-job1.schedule: "@every 5s"
      ofelia.job-exec.test-job1.command: "/bin/sh -c 'echo hello'"

Here is the output:

$> docker-compose  up                                                                                                                                               
Recreating docker_scheduler_1 ... done
Creating docker_test_schedule_1 ... done
Attaching to docker_scheduler_1, docker_test_schedule_1
scheduler_1      | scheduler.go:35 ▶ NOTICE New job registered "my-test-job" - "echo 'still running'" - "@daily"
scheduler_1      | scheduler.go:55 ▶ DEBUG Starting scheduler with 1 jobs

As you can see, the scheduler only registers the one job-local configuration, it does not discover the one from my second container.

I've based the config on the docker-compose file I saw in this issue: #76, on that page in the text I see it seems to work fine, the output in the text in that issue shows two jobs registered.

Using:
Docker 18.09.7
Docker-compose 1.23.2
Ofelia: latest pull from dockerhub.

I'm hoping there's something simple and obvious I'm doing wrong. Is there any kind of additional debugging output I can use to check why its not working?

@Trane9991
Copy link
Collaborator

Trane9991 commented Nov 19, 2019

Hey, problem is that ofelia can't discover labels in runtime, it reads the label on start. This means that the container must be running before ofelia.

So in your case, to fix your docker-compose, you need to change the dependencies.

So now, your test_schedule depends on scheduler but it needs to be another way around to work.

But yes, this is the missing feature that will need to be implemented.

@ashleysommer
Copy link
Contributor Author

ashleysommer commented Nov 19, 2019

Hi @Trane9991

That swapping around the dependencies you suggested is actually the first thing I thought of and the first thing I tried when I was debugging this yesterday. It didn't make any difference and the same problem occurred.

However just now after seeing your response, I created a new docker-compose file with the dependencies swapped around, now it does work as expected. So that was the problem.

Thanks for your help.

@ashleysommer
Copy link
Contributor Author

ashleysommer commented Nov 19, 2019

In regard to how to implement a feature to fix this, I think the only way to do it would be to somehow have a notification from the docker daemon to alert ofelia when a new container has started on the host, then ofelia can check if it has the right labels, and can register a new scheduled task.

That sounds like its easy on the surface, but likely hard to properly implement.

@Trane9991
Copy link
Collaborator

Trane9991 commented Nov 20, 2019

@ashleysommer most likely ofelia will need to poll docker for new containers every few secs and update the jobs configuration. However not sure if this will be easy to fit in the current architecture.

@4n70w4
Copy link

4n70w4 commented Apr 17, 2020

@helmut72
Copy link

helmut72 commented Jun 24, 2020

Hey, problem is that ofelia can't discover labels in runtime, it reads the label on start. This means that the container must be running before ofelia.

This becomes a showstopper for me, because I use some docker-compose files and even if I use one only, it's required to check if other containers are running or have a big list in 'depends on'.

@rdelcorro
Copy link

rdelcorro commented Jan 5, 2021

Fixed here: #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants