I am deploying a Django application using Docker onto ECS and encountering an issue where Celery commands specified in my entrypoint.sh script are not being recognized, resulting in errors. My Docker setup involves using Celery for asynchronous task processing, with separate containers for Celery workers and beat scheduled tasks. I get the following error messages when I create the ECS which includes the celery worker and beat as containers within the same task definition.
Error Messages:
/app/entrypoint.sh: line 28: exec: celery -A healthcare_project worker -l info: not found
/app/entrypoint.sh: line 28: exec: celery -A healthcare_project beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler: not found
Entrypoint Script (entrypoint.sh):
#!/bin/bash
# Exit script in case of error
set -e
# Apply database migrations
echo "Applying database migrations..."
python manage.py migrate --noinput
# Collect static files
echo "Collecting static files..."
python manage.py collectstatic --noinput --clear
# Debugging: List installed packages and show PATH
echo "Installed Python packages:"
pip freeze
echo "Current PATH in Docker: $PATH"
# Check if celery command is passed
if [[ "$1" == "celery" ]]; then
# Shift command line arguments left
shift 1
# Execute the celery command with the passed arguments
exec /usr/local/bin/celery -A healthcare_project "$@"
else
# Start command passed to the script. For example:
# if passed "gunicorn", it starts Gunicorn; if passed "daphne", it starts Daphne
exec "$@"
fi
Dockerfile
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Set work directory
WORKDIR /app
# Install dependencies
COPY HealthApp/requirements.txt /app/
RUN pip install --upgrade pip && pip install -r requirements.txt
# Copy the application files from healthcare_project
COPY . /app/
# Copy the shared entrypoint script
# The entrypoint.sh file is now within the HealthApp directory
COPY HealthApp/entrypoint.sh /app/
RUN chmod +x /app/entrypoint.sh
# Expose port 8000 for web connections
EXPOSE 8000
# Use the entrypoint script to configure the container
ENTRYPOINT ["/app/entrypoint.sh"]
# Start Gunicorn for the Django project
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "healthcare_project.wsgi:application"]
Attempts to Resolve:
1. Verified that Celery is installed by checking with pip freeze.
2. Checked the PATH and confirmed that /usr/local/bin is included.
3. Celery is present in the requirements.txt
Despite these attempts, the issue persists. How can I correctly configure the entrypoint.sh script to recognize and execute the Celery commands without errors?