Running web repo locally using Docker failing
- Dominant language
- JavaScript
- Stars
- 1.8k
- Forks
- 776
- PR merge metrics
- No merged PRs in 30d
Description
**Overview**
When trying to run through the instructions to bring up the web repository for [local development using docker in the docs folder.](https://github.com/gitcoinco/web/blob/master/docs/RUNNING_LOCALLY_DOCKER.md). The web
**Steps To Reproduce**
Steps to reproduce the behavior:
1. clone repo and copy env file
```
git clone https://github.com/gitcoinco/web.git
cd web
cp app/app/local.env app/app/.env
```
2. Replace DATABASE_URL in env file as specified
```
DATABASE_URL=psql://gitcoin_user:password@localhost:5432/gitcoin
# If setting DATABASE_URL for local development server use following
# DATABASE_URL=psql://gitcoin_user:password@localhost:5432/gitcoin
```
3. Run docker compose in detached mode `docker-compose up -d --build`
4. Navigate to https://localhost:8000 and there is nothing being served
5. Check docker and two of the containers are cycling through restarting - web-gitcoin-web-1
and web-gitcoin-scheduler-1
**Observed behaviour**
Docker containers appear not to be communicating together. Potentially a conflict with port usage - specifically port 5432
**Expected behavior**
A webpage built from the local web repo to display on localhost:8000
**Screenshots**

**Additional context**
Logs - web-gitcoin-web-1 container
```
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 59, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/utils.py", line 62, in inner
ret = func(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/commands/runserver_plus.py", line 262, in handle
self.inner_run(options)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/commands/runserver_plus.py", line 305, in inner_run
self.check_migrations()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
- Generated: /code/app/assets/v2/bundled/css/leaderboard.a0d3f9.css
- Generated: /code/app/assets/v2/bundled/js/unveil.ca3bee.js
- Generated: /code/app/assets/v2/bundled/css/onepagesubmit.0acc37.css
- Generated: /code/app/assets/v2/bundled/css/presskit.5d20a1.css
System check identified some issues:
WARNINGS:
?: (debug_toolbar.W001) debug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.
HINT: Add debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.
Collect template files from all apps:
- 646 templates discovered
Clear bundle directories:
- Deleting 0 assets from: /code/app/assets/v2/bundles/js
- Deleting 6 assets from: /code/app/assets/v2/bundled/js
- Deleting 0 assets from: /code/app/static/v2/bundles/js
- Deleting 0 assets from: /code/app/static/v2/bundled/js
- Deleting 0 assets from: /code/app/assets/v2/bundled/scss
- Deleting 7 assets from: /code/app/assets/v2/bundled/css
- Deleting 0 assets from: /code/app/static/v2/bundled/css
Start generating bundled assets (using app.bundleContext as context):
System check identified some issues:
WARNINGS:
?: (debug_toolbar.W001) debug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.
HINT: Add debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.
- Generated: /code/app/assets/v2/bundled/js/tip_dependancies.8fb2ba.js
- Generated: /code/app/assets/v2/bundled/css/activity.e26ed8.css
- Generated: /code/app/assets/v2/bundled/css/avatar_landing.77249e.css
- Generated: /code/app/assets/v2/bundled/css/tag.3d938f.css
- Generated: /code/app/assets/v2/bundled/css/unsubscribe_email.6b6891.css
- Generated: /code/app/assets/v2/bundled/js/jquery.bc2156.js
- Generated: /code/app/assets/v2/bundled/js/bootstrap.e95c08.js
- Generated: /code/app/assets/v2/bundled/js/gas.998246.js
- Generated: /code/app/assets/v2/bundled/js/jquery-gas.1fd48e.js
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 59, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/utils.py", line 62, in inner
ret = func(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/commands/runserver_plus.py", line 262, in handle
self.inner_run(options)
File "/usr/local/lib/python3.6/dist-packages/django_extensions/management/commands/runserver_plus.py", line 305, in inner_run
self.check_migrations()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
```
Logs - web-gitcoin-scheduler-1 container
```
INFO 2022-04-28 18:14:09,845 schedulers 8 140102681470784 Writing entries...
ERROR 2022-04-28 18:14:09,845 schedulers 8 140102681470784 Database error while sync: OperationalError('could not connect to server: Connection refused\n\tIs the server running on host "localhost" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432?\ncould not connect to server: Cannot assign requested address\n\tIs the server running on host "localhost" (::1) and accepting\n\tTCP/IP connections on port 5432?\n',)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django_celery_beat/schedulers.py", line 238, in sync
with transaction.atomic():
File "/usr/local/lib/python3.6/dist-packages/cacheops/transaction.py", line 70, in __enter__
self._no_monkey.__enter__(self)
File "/usr/local/lib/python3.6/dist-packages/django/db/transaction.py", line 175, in __enter__
if not connection.get_autocommit():
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 379, in get_autocommit
self.ensure_connection()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
```
Contributor guide
Research direction
Start with docs/RUNNING_LOCALLY_DOCKER.md, app/app/.env, and the reported `docker-compose up -d --build` workflow; inspect the web and scheduler container logs alongside the PostgreSQL connection error. Reproduce the setup and determine why the containers cannot connect, then verify that the containers remain running and the application is served at localhost:8000.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose, postgresql, python
- Domain
- backend, databases, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100