You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Django+Celery+Redis时遭遇Error 99问题求助

Fixing Error 99 When Deploying Django + Celery + Redis with Docker Compose

Hey there, let's break down how to fix that Error 99 (usually "Cannot assign requested address") you're hitting, plus fill in the missing pieces for your Celery + Redis setup since you mentioned planning to use them.

1. The Immediate Fix: Correct Your Django Runserver Command

Looking at your docker-compose.yml, the command for your python service has a typo in the bind address:

python manage.py runserver 0.0.0....

That malformed address is the direct cause of Error 99—Django can't bind to an invalid address. Replace it with:

bash -c " cd /home/django/API && python manage.py runserver 0.0.0.0:8000"

0.0.0.0 tells Django to bind to all network interfaces in the container, which lets other containers and your host access the server.

2. Add Missing Redis & Celery Services to Docker Compose

You mentioned using Redis as Celery's result backend, but your current config doesn't include either a Redis service or a Celery service. Without these, Celery won't run at all, even after fixing the Django server.

Update your docker-compose.yml to include these two services:

version: '3'  # Add this line at the top if you don't have it
services:
  python:
    image: python:latest
    restart: always
    expose:
      - "8000"
    volumes:
      - ~/django/902Scratch/API:/home/django/API
      - /var/sb2_files:/var/sb2_files
      - /home/tuopinpin/JudgeServer/tests/test_case:/test_case
    links:
      - celery:celery
      - redis:redis  # Link to Redis too
    command: bash -c " cd /home/django/API && python manage.py runserver 0.0.0.0:8000"

  redis:
    image: redis:latest
    restart: always
    expose:
      - "6379"  # Default Redis port

  celery:
    image: python:latest
    restart: always
    volumes:
      - ~/django/902Scratch/API:/home/django/API
      - /var/sb2_files:/var/sb2_files
      - /home/tuopinpin/JudgeServer/tests/test_case:/test_case
    links:
      - redis:redis
    command: bash -c "cd /home/django/API && celery -A your_project_name worker --loglevel=info"
  • Replace your_project_name with the name of your Django project folder (the one containing settings.py).
  • The redis service uses the official Redis image and exposes the default port 6379.
  • The celery service shares the same volumes as your Django service and runs the Celery worker command.

3. Configure Django to Use Redis for Celery

In your Django project's settings.py, add these lines to connect Celery to Redis:

# settings.py
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'

redis://redis:6379/0 works because Docker Compose uses service names as hostnames—so the celery service can reach the redis service using the hostname redis.

4. Test the Fix

After making these changes:

  • Stop any running containers: docker-compose down
  • Start the services: docker-compose up -d
  • Check logs to confirm everything is running:
    • docker-compose logs python (verify Django started without errors)
    • docker-compose logs celery (verify Celery worker connected to Redis)
    • docker-compose logs redis (verify Redis is running)

If you still run into issues, double-check that:

  • Your Django project name is correctly used in the Celery command
  • The volumes are mounted correctly (no permission issues)
  • Port 8000 on your host isn't being used by another service (though since you're using expose instead of ports, this is less likely to cause Error 99)

内容的提问来源于stack exchange,提问作者VivianSnow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:04:57