我正在尝试在单独的docker容器中与django/redisdocker设置一起运行celery。
当我运行docker-compose up -d --build
时,我的日志通过docker-compose logs --tail=0 --follow
显示celery_1
容器反复向控制台发送垃圾邮件
Usage: nc [OPTIONS] HOST PORT - connect
nc [OPTIONS] -l -p PORT [HOST] [PORT] - listen
-e PROG Run PROG after connect (must be last)
-l Listen mode, for inbound connects
-lk With -e, provides persistent server
-p PORT Local port
-s ADDR Local address
-w SEC Timeout for connects and final net reads
-i SEC Delay interval for lines sent
-n Don't do DNS resolution
-u UDP mode
-v Verbose
-o FILE Hex dump traffic
-z Zero-I/O mode (scanning)
我能够通过从docker-compose.yaml
中删除芹菜服务并在docker-compose up -d --build
后手动运行docker exec -it backend_1 celery -A proj -l info
来使芹菜正常工作。如何在docker-compose.yaml
中复制此手动过程的功能?
我的docker-compose.yaml
看起来像
version: '3.7'
services:
backend:
build: ./backend
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./backend/app/:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./.env.dev
depends_on:
- db
- redis
links:
- db:db
celery:
build: ./backend
command: celery -A proj worker -l info
volumes:
- ./backend/app/:/usr/src/app/
depends_on:
- db
- redis
redis:
image: redis:5.0.6-alpine
command: redis-server
expose:
- "6379"
db:
image: postgres:12.0-alpine
ports:
- 5432:5432
volumes:
- /tmp/postgres_data:/var/lib/postgresql/data/
我发现问题是我的芹菜服务无法解析 SQL 主机。这是因为我的 SQL 主机是在 .env.dev 中定义的,芹菜服务无权访问该主机。我添加了
env_file:
- ./.env.dev
到芹菜服务,一切都按预期工作。