我有一个运行Django的API应用程序。我有2个容器,
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5620d232e96c django_worker:v1 "/bin/bash" 4 days ago Up 4 days drunk_goldberg
eeb5b0e8dbce django_main:v1 "./main.sh" 4 days ago Up 4 days 0.0.0.0:8000->8000/tcp sick_almeida
两者都托管相同的代码库。主要是暴露API,另一个是通过命令运行芹菜工作者,
su -m celery -c "celery --app=XXX.celery:app worker -Q ${QUEUE} --loglevel=INFO --autoscale=10,3"
两个容器中的 Django设置文件是
BROKER_URL = 'redis://10.1.1.8:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
但是在主容器中我收到错误
ERROR:XXX.views:Exception Raised:
Traceback (most recent call last):
File "/opt/XXX/XXX/views.py", line 169, in upgrade
ABC.delay(username,password,ip,device,manifest,peer_ip)
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 453, in delay
return self.apply_async(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 560, in apply_async
**dict(self._get_exec_options(), **options)
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 354, in send_task
reply_to=reply_to or self.oid, **options
File "/usr/local/lib/python2.7/dist-packages/celery/app/amqp.py", line 305, in publish_task
**kwargs
File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 172, in publish
routing_key, mandatory, immediate, exchange, declare)
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 457, in _ensured
interval_max)
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 369, in ensure_connection
interval_start, interval_step, interval_max, callback)
File "/usr/local/lib/python2.7/dist-packages/kombu/utils/__init__.py", line 243, in retry_over_time
return fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 237, in connect
return self.connection
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 741, in connection
self._connection = self._establish_connection()
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 696, in _establish_connection
conn = self.transport.establish_connection()
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
conn = self.Connection(**opts)
File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 165, in __init__
self.transport = self.Transport(host, connect_timeout, ssl)
File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 186, in Transport
return create_transport(host, connect_timeout, ssl)
File "/usr/local/lib/python2.7/dist-packages/amqp/transport.py", line 299, in create_transport
return TCPTransport(host, connect_timeout)
File "/usr/local/lib/python2.7/dist-packages/amqp/transport.py", line 95, in __init__
raise socket.error(last_err)
error: [Errno 111] Connection refused
现在如果我从主容器测试连接就好了。
有什么想法吗?