title: Docker container Django not connecting to postgresql
body: <p>I am having trouble starting up the django app. It seems to freeze when it prints out</p>
  <p>&quot;System check identified 6 issues (0 silenced).&quot;</p>
  <p>I believe this is because django is not connected to the postgresql database. I am really unsure of what the problem could be because it was working fine a year ago, and when I am starting it up now it is broken.</p>
  <p><em><strong>Here is the output for postgresql from the docker container log</strong></em></p>
  <pre><code>/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
  
  
  2022-06-13 03:35:26.151 UTC [48] LOG:  received fast shutdown request
  
  waiting for server to shut down....2022-06-13 03:35:26.155 UTC [48] LOG:  aborting any active transactions
  
  2022-06-13 03:35:26.156 UTC [48] LOG:  background worker &quot;logical replication launcher&quot; (PID 55) exited with exit code 1
  
  2022-06-13 03:35:26.156 UTC [50] LOG:  shutting down
  
  2022-06-13 03:35:26.204 UTC [48] LOG:  database system is shut down
  
   done
  
  server stopped
  
  
  PostgreSQL init process complete; ready for start up.
  
  
  initdb: warning: enabling &quot;trust&quot; authentication for local connections
  
  You can change this by editing pg_hba.conf or using the option -A, or
  
  --auth-local and --auth-host, the next time you run initdb.
  
  2022-06-13 03:35:26.273 UTC [1] LOG:  starting PostgreSQL 14.3 (Debian 14.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
  
  2022-06-13 03:35:26.273 UTC [1] LOG:  listening on IPv4 address &quot;0.0.0.0&quot;, port 5432
  
  2022-06-13 03:35:26.273 UTC [1] LOG:  listening on IPv6 address &quot;::&quot;, port 5432
  
  2022-06-13 03:35:26.281 UTC [1] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  
  2022-06-13 03:35:26.290 UTC [60] LOG:  database system was shut down at 2022-06-13 03:35:26 UTC
  
  2022-06-13 03:35:26.291 UTC [61] FATAL:  the database system is starting up
  
  2022-06-13 03:35:26.297 UTC [1] LOG:  database system is ready to accept connections
  </code></pre>
  <p><em><strong>django docker logs:</strong></em></p>
  <pre><code>
    File &quot;/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py&quot;, line 26, in inner
  
      return func(*args, **kwargs)
  
    File &quot;/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py&quot;, line 187, in get_new_connection
  
      connection = Database.connect(**conn_params)
  
    File &quot;/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py&quot;, line 122, in connect
  
      conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  
  django.db.utils.OperationalError: FATAL:  the database system is starting up
  </code></pre>
  <p>Here is my <em><strong>docker-compose.yml file</strong></em></p>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.7&quot;
  
  services:
    postgresql:
      container_name: postgresql
  
      image: postgres:14.3-bullseye
      restart: always
  
      volumes:
        - postgresql_data:/var/lib/postgresql/data
  
      environment:
        - POSTGRES_DB=postgres
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=12345678
  
    django:
      container_name: django
      build: .
      # command: ENTERYPOINT
      volumes:
        - static_volume:/app/static
  
      depends_on:
        - postgresql
  
    nginx:
      container_name: nginx
      build: ./nginx/.
      volumes:
        - static_volume:/app/static
      ports:
        - &quot;80:80&quot;
        - &quot;443:443&quot;
      depends_on:
        - django
  
  volumes:
    static_volume:
    postgresql_data:
  </code></pre>
  <p><em><strong>Django settings for docker postgresql database</strong></em></p>
  <pre class="lang-py prettyprint-override"><code># docker database
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'NAME': 'postgres',
          'USER': 'postgres',
          'PASSWORD': '12345678',
          'HOST': 'postgresql',
          'PORT': 5432,
      }
  }
  </code></pre>
  <p>Django Dockerfile</p>
  <pre class="lang-yaml prettyprint-override"><code>FROM python:3.9-buster
  
  WORKDIR /app
  
  RUN apt update &amp;&amp; apt upgrade -y
  RUN pip install -U pip
  
  
  COPY requirements.txt /app/
  RUN pip install -r requirements.txt
  
  COPY . /app/
  
  COPY ./django-enterypoint.sh /app/
  
  ENTRYPOINT [ &quot;sh&quot;, &quot;django-enterypoint.sh&quot; ]
  </code></pre>
  <p><em><strong>Django django-enterypoint.sh file</strong></em></p>
  <pre class="lang-bash prettyprint-override"><code>python manage.py collectstatic --no-input
  python manage.py migrate --no-input
  
  python manage.py runserver 0.0.0.0:8000
  
  # gunicorn wall.wsgi:application --bind 0.0.0.0:8000
  </code></pre>