3

My docker-compose file is as follows:

version: '3'

services:
  db:
    image: mongo:4.2
    container_name: mongo-db
    restart: always
    environment:
      MONGO_INITDB_DATABASE: VMcluster
    ports:
      - "16006:27017"
    volumes:
      - ./initdb.js:/docker-entrypoint-initdb.d/initdb.js

  web:
    build:
      context: .
      dockerfile: Dockerfile_Web
    command: python manage.py runserver 0.0.0.0:8000
    container_name: cluster-monitor-web
    volumes:
      - .:/vmCluster_service
    ports:
      - "9900:8000"
    depends_on:
      - db

  cronjobs:
    build:
      context: .
      dockerfile: Dockerfile_Cron
    command: ["cron", "-f"]
    container_name: cluster-monitor-cron

I want to implement a feature where the user should be able to update the crontab from the Django web. I'm done with Django part i.e python code for backend. But the Django web container is not able to access the crontab container. how can I make Django web container to access the crontab container and update the crontab?

Im using python-crontab module in django which throws an error :

"[Errno 2] No such file or directory: '/usr/bin/crontab': '/usr/bin/crontab'"

Tms91
  • 3,456
  • 6
  • 40
  • 74
rakesh kotian
  • 232
  • 1
  • 5
  • 30
  • 1
    there is a workaround - if you have mounted both containers on the same system folder, you try setting up a named pipe (file based queue) and write a listener in the crontab container. – skybunk Sep 19 '19 at 22:02
  • check this - https://stackoverflow.com/a/49873529/8872639 – skybunk Sep 20 '19 at 02:20
  • @skybunk you mean I have to use something like [kafka](https://kafka.apache.org)? – rakesh kotian Sep 20 '19 at 05:41
  • 1
    You essentially need a medium to transfer the command from one container to the other. A producer at one end and a consumer at the other. Kafka would fit the use case, but it could be an overkill if your scale is small. – skybunk Sep 20 '19 at 05:50

0 Answers0