title: Dockerize Django with Celery worker/beat, RabbitMQ and postgresql
body: <p>I want to setup docker-compose for my app, which contains Django, Celery (+Beat), RabbitMQ and PSQL. My problem is that celery beat container does not work as intended (does not schedule a task with interval 10s).</p>
  <p>Docker logs - celery beat wakes up in 5.00 minutes, celery worker works fine</p>
  <pre><code>celery-worker_1  | [2021-03-29 21:05:58,201: INFO/MainProcess] mingle: all alone
  celery-worker_1  | [2021-03-29 21:05:58,225: WARNING/MainProcess] /usr/local/lib/python3.9/site-packages/celery/fixups/django.py:205: UserWarning: Using settings.DEBUG leads to a memory
  celery-worker_1  |             leak, never use this setting in production environments!
  celery-worker_1  |   warnings.warn('''Using settings.DEBUG leads to a memory
  celery-worker_1  | [2021-03-29 21:05:58,225: INFO/MainProcess] celery@247ea26ee17b ready.
  celery-beat_1    | [2021-03-29 21:06:00,525: DEBUG/MainProcess] Setting default socket timeout to 30
  celery-beat_1    | [2021-03-29 21:06:00,526: INFO/MainProcess] beat: Starting...
  celery-beat_1    | [2021-03-29 21:06:00,749: DEBUG/MainProcess] Current schedule:
  celery-beat_1    | &lt;ScheduleEntry: celery.backend_cleanup celery.backend_cleanup() &lt;crontab: 0 4 * * * (m/h/d/dM/MY)&gt;
  celery-beat_1    | [2021-03-29 21:06:00,749: DEBUG/MainProcess] beat: Ticking with max interval-&gt;5.00 minutes
  celery-beat_1    | [2021-03-29 21:06:00,751: DEBUG/MainProcess] beat: Waking up in 5.00 minutes.
  </code></pre>
  <p>Dockerfile</p>
  <pre><code>FROM python:3
  ENV PYTHONBUFFERED=1
  WORKDIR /usr/src/app
  COPY requirements.txt ./
  RUN pip install -r requirements.txt
  </code></pre>
  <p>docker-compose.yml</p>
  <pre><code>version: '3.8'
  
  services:
    server:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/usr/src/app
      ports:
        - &quot;8000:8000&quot;
      env_file:
        - .env
      depends_on:
        - pgdb
        - rabbit
        - celery-worker
  
    celery-worker:
      build: .
      command: sh -c 'sleep 8; celery -A core worker -l INFO'
      env_file:
        - .env
      volumes:
        - .:/usr/src/app
      depends_on:
        - pgdb
        - rabbit
  
    celery-beat:
      build: .
      command: sh -c 'sleep 10; celery -A core beat -l debug'
      env_file:
        - .env
      volumes:
        - .:/usr/src/app
      depends_on:
        - pgdb
        - rabbit
        - celery-worker
  
    pgdb:
      image: postgres
      env_file:
        - .env
      volumes:
        - pgdata:/var/lib/postgresql/data/
      ports:
      - &quot;5432:5432&quot;
      restart: on-failure
  
    rabbit:
      image: &quot;rabbitmq:3-management-alpine&quot;
      env_file:
        - .env
      ports:
      - &quot;5672:5672&quot;
      - &quot;15672:15672&quot;
      restart: on-failure
  
  volumes:
    pgdata: {}
  </code></pre>
  <p>settings.py</p>
  <pre><code>CELERY_BROKER_URL = 'amqp://admin:mypass@rabbit:5672/'
  CELERY_RESULT_BACKEND = 'db+postgresql://news_user:news@pgdb/news'
  
  CELERY_BEAT_SCHEDULE = {
      'scheduled_task': {
          'task': 'news.tasks.get_news',
          'schedule': 10.0
      }
  }
  </code></pre>