【发布时间】:2022-01-07 12:52:04
【问题描述】:
我有一个部署在 Docker 容器中的 Django 应用程序。
我有 3 个配置环境:dev、preprod 和 prod。 dev 是我的本地环境(localhost),preprod/prod 是远程 linux 环境。 它在使用“公共”Redis 服务器和标准配置时有效。
但我需要使用我们自己的 Redis 部署在远程服务器 (192.168.xx.xx) 中的 Docker 容器中,名称为 container redis_cont。
而且我真的不知道如何配置。不知道有没有可能? 我将不胜感激。
docker-compose
version: '3.7'
services:
web:
restart: always
build:
context: ./app
dockerfile: Dockerfile.dev
restart: always
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./app:/usr/src/app
ports:
- 8000:8000
env_file:
- ./.env.dev
entrypoint: [ "/usr/src/app/entrypoint.dev.sh" ]
depends_on:
- redis
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 50
redis:
container_name: redis_cont <= container running in remote linux server
image: "redis:alpine"
celery:
build:
context: ./app
dockerfile: Dockerfile.dev
command: celery -A core worker -l info
volumes:
- ./app:/usr/src/app
env_file:
- ./.env.dev
depends_on:
- web
- redis
celery-beat:
build:
context: ./app
dockerfile: Dockerfile.dev
command: celery -A core beat -l info
volumes:
- ./app:/usr/src/app
env_file:
- ./.env.dev
depends_on:
- web
- redis
settings.py
CELERY_BROKER_URL = 'redis://redis:6379'
CELERY_RESULT_BACKEND = 'redis://redis:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_BEAT_SCHEDULE = {
'hello': {
'task': 'project.tasks.hello',
'schedule': crontab() # execute every minute
},
}
【问题讨论】:
标签: django docker redis django-celery