我有一个django渠道容器和一个芹菜工人,我正在尝试连接到芹菜容器内的django渠道容器,但是,我发现很难连接。我在http://127.0.0.1:8000/上运行了一个django服务器。这就是我的docker-compose文件的样子
web:
restart: always
tty: true
build: ./web/
working_dir: /data/web/fileshiffty
expose:
- "8000"
ports:
- "8000:8000"
links:
- postgres:postgres
- redis:redis
env_file: env
volumes:
- ./web:/data/web
command: bash -c "python3 manage.py runserver 0.0.0.0:8000"
postgres:
restart: always
image: postgres:latest
volumes_from:
- data
volumes:
- ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./backups/postgresql:/backup
env_file:
- env
expose:
- "5432"
redis:
restart: always
image: redis:latest
expose:
- "6379"
worker:
build: ./web/
working_dir: /data/web/fileshiffty
command: bash -c "celery -A fileshiffty worker --loglevel=DEBUG"
volumes:
- ./web:/data/web
links:
- postgres:postgres
- redis:redis
- web:web
data:
restart: always
image: alpine
volumes:
- /var/lib/postgresql
command: "true"
但是,在我的芹菜任务中,它要求它连接到具有URL ws://127.0.0.1:8000/ws/converter/public/
的Web套接字。这就是我的任务的样子
# Create your tasks here
from __future__ import absolute_import, unicode_literals
from celery import shared_task
import img2pdf
import os
import websocket
import json
import boto
from boto.s3.key import Key
@shared_task
def convert_file_to_pdf(file_name_on_cdn):
ws = websocket.WebSocket()
ws.connect('ws://web/ws/converter/public/')
ws.send(json.dumps({
'message': '{}'.format(file_name_on_cdn),
'progress': 0}))
# some other stuff
但是,在运行任务时我一直收到以下错误
worker_1 | [2018-03-21 16:19:03,392: ERROR/ForkPoolWorker-2] Task api.tasks.convert_file_to_pdf[2fb26db9-7dd5-4b57-9242-fd61e743952d] raised unexpected: ConnectionRefusedError(111, 'Connection refused')
worker_1 | Traceback (most recent call last):
worker_1 | File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 374, in trace_task
worker_1 | R = retval = fun(*args, **kwargs)
worker_1 | File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 629, in __protected_call__
worker_1 | return self.run(*args, **kwargs)
worker_1 | File "/data/web/fileshiffty/api/tasks.py", line 30, in convert_file_to_pdf
worker_1 | ws.connect('ws://web/ws/converter/public/')
worker_1 | File "/usr/local/lib/python3.6/site-packages/websocket/_core.py", line 217, in connect
worker_1 | options.pop('socket', None))
worker_1 | File "/usr/local/lib/python3.6/site-packages/websocket/_http.py", line 70, in connect
worker_1 | sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
worker_1 | File "/usr/local/lib/python3.6/site-packages/websocket/_http.py", line 131, in _open_socket
worker_1 | raise err
worker_1 | File "/usr/local/lib/python3.6/site-packages/websocket/_http.py", line 116, in _open_socket
worker_1 | sock.connect(address)
worker_1 | ConnectionRefusedError: [Errno 111] Connection refused
很明显它无法连接到网址。我甚至试过设置ws.connect('ws://web/ws/converter/public/')
但是,这似乎也没有用。任何帮助,将不胜感激。一直试图弄清楚多少小时的错误
答案 0 :(得分:0)
看起来我所要做的就是指定我的Django应用程序运行的端口是端口8000,所以我只需要将ws.connect('ws://web:8000/ws/converter/public/')
更改为{{1}}