-1

I found a Django project and failed to get it running in Docker container in the following way:

  1. git clone https://github.com/hotdogee/django-blast.git

  2. $ cat requirements.txt in this files the below dependencies had to be updated:

    • kombu==3.0.30
    • psycopg2==2.8.6

I have the following Dockerfile:

FROM python:2
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

For docker-compose.yml I use:

version: "3"

services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  dbi5k:
    image: postgres
    volumes:
      - ./data/dbi5k:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=django_i5k
      - POSTGRES_USER=django
      - POSTGRES_PASSWORD=postgres


  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
    links:
      - db

I had to change:

$ vim i5k/settings_prod.py
DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'postgres',
    'USER': 'postgres',
    'PASSWORD': 'postgres',
    'HOST': 'db',
    'PORT': '5432',
    }
}

and

$ vim i5k/settings.py
    DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django_i5k',
        'USER': 'django',
        'PASSWORD': 'postgres',
        'HOST': 'dbi5k',
        'PORT': '5432',
        }
    }

Unfortunately, I got this error:

web_1    | Performing system checks...
web_1    | 
web_1    | System check identified no issues (0 silenced).
web_1    | Unhandled exception in thread started by <function wrapper at 0x7f80449f4850>
web_1    | Traceback (most recent call last):
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 223, in wrapper
web_1    |     fn(*args, **kwargs)
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run
web_1    |     self.check_migrations()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 164, in check_migrations
web_1    |     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
web_1    |     self.loader = MigrationLoader(self.connection)
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
web_1    |     self.build_graph()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 180, in build_graph
web_1    |     self.applied_migrations = recorder.applied_migrations()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
web_1    |     self.ensure_schema()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
web_1    |     if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
web_1    |     cursor = self.make_debug_cursor(self._cursor())
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
web_1    |     self.ensure_connection()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1    |     self.connect()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
web_1    |     six.reraise(dj_exc_type, dj_exc_value, traceback)
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1    |     self.connect()
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
web_1    |     self.connection = self.get_new_connection(conn_params)
web_1    |   File "/usr/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 172, in get_new_connection
web_1    |     connection = Database.connect(**conn_params)
web_1    |   File "/usr/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 127, in connect
web_1    |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
web_1    | django.db.utils.OperationalError: could not connect to server: Connection refused
web_1    |  Is the server running on host "dbi5k" (192.168.32.3) and accepting
web_1    |  TCP/IP connections on port 5432?

How is it possible to fix it?

Thank you in advance

user977828
  • 205
  • 4
  • 15

1 Answers1

0

Similarly to the last issue with the db host, the github generic version doesn't specify any password: here and here

jabbson
  • 561
  • 1
  • 8
  • Thank you, I updated the linked files and docker-compose.yml in my question. Unfortunately, I ran into `web_1 | django.db.utils.OperationalError: could not connect to server: Connection refused web_1 | Is the server running on host "dbi5k" (192.168.32.3) and accepting web_1 | TCP/IP connections on port 5432?`. What did I miss? – user977828 May 18 '21 at 02:40
  • I am not sure I agree with the approach to replace one question with another when the initial one is solved. Instead it is better to rate the answer (if helpful) and create a separate post/questions with a new problem. This way we have a record of both questions where other users can benefit from reading them and applying to their situations. As for your question. Did you make sure the containers are running? – jabbson May 18 '21 at 03:18