Docker部署Django+Celery+Redis时遭遇Error 99问题求助
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_namewith the name of your Django project folder (the one containingsettings.py). - The
redisservice uses the official Redis image and exposes the default port 6379. - The
celeryservice 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
exposeinstead ofports, this is less likely to cause Error 99)
内容的提问来源于stack exchange,提问作者VivianSnow

