0

I'm trying to run redis and celery separately in two docker containers.

docker run -p 6379:6379 --name some-redis -d redis

and

docker run --link some-redis:redis -e CELERY_BROKER_URL=redis://localhost:6739/0 --name some-celery -d celery

But it looks like celery doesn't see redis.

BROKER_URL = 'redis://localhost:6379/0'
app = Celery('tasks', broker=BROKER_URL)

@app.task
def add():
    text = 'hello !'
    url = 'https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}'.format(token, chat_id, text)
    requests.get(url)

res = add.delay()
print(res)

print(res) return 7e9b395a-bb7d-4a7a-b390-116cb7a47a26

I think this means that redis is working correctly.

How do I debug celery?

I have tried:

docker run --link some-redis -e CELERY_BROKER_URL=redis://localhost:6379/0 --rm celery celery status

However, I get this error.

File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 756, in connection
    self._connection = self._establish_connection()
  File "/usr/local/lib/python3.5/site-packages/kombu/connection.py", line 711, in _establish_connection
    conn = self.transport.establish_connection()
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/virtual/__init__.py", line 809, in establish_connection
    self._avail_channels.append(self.create_channel(self))
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/virtual/__init__.py", line 791, in create_channel
    channel = self.Channel(connection)
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/redis.py", line 466, in __init__
    self._disconnect_pools()
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/redis.py", line 484, in _disconnect_pools
    self._async_pool.disconnect()
  File "/usr/local/lib/python3.5/site-packages/redis/connection.py", line 921, in disconnect
    connection.disconnect()
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/redis.py", line 866, in disconnect
    channel._on_connection_disconnect(self)
  File "/usr/local/lib/python3.5/site-packages/kombu/transport/redis.py", line 498, in _on_connection_disconnect
    raise get_redis_ConnectionError()
redis.exceptions.ConnectionError

Any help would be appreciated.

Camp Nerd
  • 65
  • 8
  • 1
    `localhost` in Docker usually means "this container"; the `--link` option is obsolete. You need to `docker network create` a network, run both containers `--net` that network name, and then the other container's `--name some-redis` will be usable as a host name to connect to Redis. Running this stack under Docker Compose will automatically create the network for you and save retyping the commands. – David Maze Oct 22 '21 at 18:01

0 Answers0