skip to Main Content

I’ve followed each step of part 1 chapter 4 and literally copy pasted the code as shown.

docker-compose is able to build the containers but I always get the Waiting for PostgresSQL to become available being logged from all the other containers as shown below. docker-compose logs

Following is the output of docker ps -a. From which I can see that all containers are running in their respective ports.
docker ps -a logs

I checked the docker container logs of the db and it shows to be running.
postgres container logs

But, I’m unable to open the Django server on port 8010 nor able to view the flower server on port 5557 because in the container logs I’m getting the message "Waiting for PostgreSQL to become available…"

Someone please help. This issue is killing me. I’ve tried to view the logs of each container and it’s showing it’s running, yet I’m not able to view the Django and flower server.

Let me know if you guys need more info.

Thanks!

Tried checking if the DB is up and running at the correct port.
checked if Redis is running.
checked the logs of each running container which points to the same message "Waiting for PostgreSQL to become available…"

2

Answers


  1. psycopg2-binary package was used.
    Using psycopg2 instead worked for me.
    This issue maybe related to Mac M1

    Login or Signup to reply.
  2. I had the same problem with this tutorial (on mac M1) and it took me many hours. The solution for me was finally to use "alpine" instead of "buster", here is my Dockerfile:

    FROM alpine:3.17.1
    
    ENV PYTHONUNBUFFERED 1
    ENV PYTHONDONTWRITEBYTECODE 1
    
    RUN apk update 
        && apk add postgresql-dev gcc python3-dev musl-dev py3-pip bash
    
    # Requirements are installed here to ensure they will be cached.
    COPY ./requirements.txt /requirements.txt
    RUN pip install -r /requirements.txt
    
    COPY ./compose/local/django/entrypoint /entrypoint
    RUN sed -i 's/r$//g' /entrypoint
    RUN chmod +x /entrypoint
    
    COPY ./compose/local/django/start /start
    RUN sed -i 's/r$//g' /start
    RUN chmod +x /start
    
    COPY ./compose/local/django/celery/worker/start /start-celeryworker
    RUN sed -i 's/r$//g' /start-celeryworker
    RUN chmod +x /start-celeryworker
    
    COPY ./compose/local/django/celery/beat/start /start-celerybeat
    RUN sed -i 's/r$//g' /start-celerybeat
    RUN chmod +x /start-celerybeat
    
    COPY ./compose/local/django/celery/flower/start /start-flower
    RUN sed -i 's/r$//g' /start-flower
    RUN chmod +x /start-flower
    
    WORKDIR /app
    
    ENTRYPOINT ["/entrypoint"]
    

    requirements.txt:

    django==4.1.4
    celery==5.2.7
    redis==4.3.4
    flower==1.2.0
    psycopg2-binary==2.9.5
    

    And may not directly related, I added start and health checks to the docker compose file, so you don’t need the postgres "ready" polling in the entrypoint script.

    Here my docker-compose.yml:

    version: '3.8'
    
    services:
      web:
        build:
          context: .
          dockerfile: ./compose/local/django/Dockerfile
        image: django_celery_example_web
        command: /start
        volumes:
          - .:/app
        ports:
          - 8010:8000
        env_file:
          - ./.env/.dev-sample
        depends_on:
          redis:
            condition: service_started
          db:
            condition: service_healthy
    
      db:
        image: postgres:14.6-alpine
        volumes:
          - postgres_data:/var/lib/postgresql/data/
        environment:
          - POSTGRES_DB=hello_django
          - POSTGRES_USER=hello_django
          - POSTGRES_PASSWORD=hello_django
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U hello_django"]
          interval: 5s
          timeout: 5s
          retries: 5
    
      redis:
        image: redis:7-alpine
        networks:
          - default
    
      celery_worker:
        build:
          context: .
          dockerfile: ./compose/local/django/Dockerfile
        image: django_celery_example_celery_worker
        command: /start-celeryworker
        volumes:
          - .:/app
        env_file:
          - ./.env/.dev-sample
        networks:
          - default
        depends_on:
          redis:
            condition: service_started
          db:
            condition: service_healthy
    
      celery_beat:
        build:
          context: .
          dockerfile: ./compose/local/django/Dockerfile
        image: django_celery_example_celery_beat
        command: /start-celerybeat
        volumes:
          - .:/app
        env_file:
          - ./.env/.dev-sample
        depends_on:
          redis:
            condition: service_started
          db:
            condition: service_healthy
    
      flower:
        build:
          context: .
          dockerfile: ./compose/local/django/Dockerfile
        image: django_celery_example_celery_flower
        command: /start-flower
        volumes:
          - .:/app
        env_file:
          - ./.env/.dev-sample
        ports:
          - 5557:5555
        depends_on:
          redis:
            condition: service_started
          db:
            condition: service_healthy
    
    volumes:
      postgres_data:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search