title: Celery task .get() not working
body: <p>I will really appreciate help with this!</p>
  
  <p>This is my first attempt at using Celery with Django in Docker containers and I can't get passed this problem after many hours of reading and experimenting.</p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>I can import the task from <code>polls.task</code> and run it using <code>.delay()</code> as follows:</p>
  
  <pre><code>python manage.py shell
  from polls.tasks import add
  task = add.delay(4,4)
  </code></pre>
  
  <p>When I run this, I can see a message through the rabbitmq container.</p>
  
  <p>If I execute task.id, i can get the task id.</p>
  
  <p>HOWEVER, if I run <code>task.get()</code>, <strong>the program just hangs</strong>. I see no action on any of the containers and I get no result.</p>
  
  <p>I have also noticed that, when I run dc-up and start all the containers, I get the following output on the worker container, which seems correct including being able to see my task registered:</p>
  
  <pre><code>worker      |  -------------- default@5d0902ad9e2a v4.1.0 (latentcall)
  worker      | ---- **** ----- 
  worker      | --- * ***  * -- Linux-4.9.87-linuxkit-aufs-x86_64-with-debian-8.10 2018-03-30 09:45:01
  worker      | -- * - **** --- 
  worker      | - ** ---------- [config]
  worker      | - ** ---------- .&gt; app:         composeexample:0x7f2f3255e320
  worker      | - ** ---------- .&gt; transport:   amqp://admin:**@rabbitmq:5672//
  worker      | - ** ---------- .&gt; results:     redis://redis:6379/0
  worker      | - *** --- * --- .&gt; concurrency: 2 (prefork)
  worker      | -- ******* ---- .&gt; task events: ON
  worker      | --- ***** ----- 
  worker      |  -------------- [queues]
  worker      |                 .&gt; default          exchange=default(direct) key=default
  worker      | 
  worker      | [tasks]
  worker      |   . polls.tasks.add
  worker      | [2018-03-30 10:45:34,722: INFO/MainProcess] Connected to amqp://admin:**@rabbitmq:5672//
  worker      | [2018-03-30 10:45:34,746: INFO/MainProcess] mingle: searching for neighbors
  worker      | [2018-03-30 10:45:35,799: INFO/MainProcess] mingle: all alone
  worker      | [2018-03-30 10:45:35,827: INFO/MainProcess] default@a7d75a442646 ready.
  </code></pre>
  
  <p>I suspect that I am missing some form of communication between rabbitmq and the worker. I also wonder if I am simply starting the worker incorrectly, or maybe not at all. I can't really tell.</p>
  
  <p>I have double-checked that my environment variables are setup in both django and worker containers.</p>
  
  <p><strong>SETUP</strong></p>
  
  <p>I have the following setup in Docker: Django, Redis(for backend), RabbitMQ(for messages), PSQL, Celery (separate container for worker)</p>
  
  <p>This is my Dockerfile:</p>
  
  <pre><code>FROM python:3
  ENV PYTHONUNBUFFERED 1
  
  ADD requirements.txt /code/
  
  WORKDIR /code/
  
  RUN apt-get update &amp;&amp; apt-get install -y \
      sudo \
      git
  
  RUN pip install --upgrade pip &amp;&amp; pip install -r requirements.txt
  
  # create unprivileged user
  RUN adduser --disabled-password --gecos '' myuser
  </code></pre>
  
  <p>Here is my docker-compose.yml:</p>
  
  <pre><code>version: '3'
  
  services:
    dbtest:
      image: postgres:10.1
      container_name: postgrestest
      expose:
        - "5432"
      volumes:
        - postgres_data:/var/lib/postgresl/data/
      networks:
        - lofi
    redis:
      image: redis:4.0.8
      container_name: redis
      networks:
        - lofi
    rabbitmq:
      image: rabbitmq:3.7.4
      container_name: rabbitmq
      env_file: .env
      ports:
        - "5672:5672"  # we forward this port because it's useful for debugging
        - "15672:15672"  # here, we can access rabbitmq management plugin
      networks:
        - lofi
    django:
      container_name: djcelerytest
      env_file: .env
      build:
        context: .
        dockerfile: Dockerfile
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/code
      ports:
        - "8000:8000"
        - "8888:8888"
      depends_on:
        - dbtest
        - rabbitmq
      networks:
        - lofi
    worker:
      env_file: .env
      build:
        context: .
        dockerfile: Dockerfile
      container_name: worker
      command: sh ./run_celery.sh
      volumes:
        - .:/code
      depends_on:
        - rabbitmq
        - redis
      networks:
        - lofi
  
  networks:
    lofi:
  
  volumes:
    postgres_data:
      external: true
  </code></pre>
  
  <p>I have the following settings in the .env file, used to set Django and worker containers:</p>
  
  <pre><code>CELERY_BROKER_URL=amqp://admin:mypass@rabbitmq//
  CELERY_RESULT_BACKEND=redis://redis:6379/0
  RABBITMQ_DEFAULT_USER=admin
  RABBITMQ_DEFAULT_PASS=mypass
  </code></pre>
  
  <p>Here is the run_celery.sh file:</p>
  
  <pre><code>#!/bin/sh
  
  # wait for RabbitMQ server to start
  sleep 10
  
  # run Celery worker for our project myproject with Celery configuration stored in Celeryconf
  su -m myuser -c "celery worker -E -A composeexample.celeryconf -Q default -n default@%h  --loglevel=INFO"
  </code></pre>
  
  <p>The task I'm trying to run is in tasks.py:</p>
  
  <pre><code>from composeexample.celeryconf import app
  from .models import AddStore
  
  @app.task
  def add(x, y):
      value = x + y
      new = AddStore(value=value)
      new.save()
      return value
  </code></pre>