My docker-compose file is as below
version: "3"
volumes:
postgres:
driver: local
services:
postgres:
image: postgres:11.1
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=mysecretpassword
- PGDATA=pgdata
volumes:
- postgres:/var/lib/postgresql/data/pgdata
backend:
build:
context: backend/
ports:
- "8000:8000"
environment:
- PRODUCTION=false
- config_file=/srv/backend/config/config.json
volumes:
- ./backend:/srv/backend
depends_on:
- postgres
frontend:
build:
context: frontend/
ports:
- "8080:8080"
volumes:
- ./frontend:/srv/frontend
scraper:
build:
context: scraper/
volumes:
- ./scraper:/srv/scraper
When I run docker I am getting below error,
backend_1 | self.ensure_connection()
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
backend_1 | return func(*args, **kwargs)
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
backend_1 | self.connect()
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
backend_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
backend_1 | self.connect()
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
backend_1 | return func(*args, **kwargs)
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
backend_1 | self.connection = self.get_new_connection(conn_params)
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
backend_1 | return func(*args, **kwargs)
backend_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
backend_1 | connection = Database.connect(**conn_params)
backend_1 | File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
backend_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
backend_1 | django.db.utils.OperationalError: could not connect to server: No route to host
backend_1 | Is the server running on host "postgres" (172.18.0.2) and accepting
backend_1 | TCP/IP connections on port 5432?
backend_1 |
backend_1 | ==> Django setup, executing: collectstatic
backend_1 |
backend_1 | 0 static files copied to '/srv/backend/django/static', 184 unmodified.
backend_1 | ==> Starting ...
config.json file is as follow
{
"production": false,
"django": {
"domain_frontend": "http://localhost:8080",
"default_from_email": “admin@mysite.com",
"secret_key": "mysecretkey",
"allowed_hosts": [
"localhost"
],
"cors_whitelist": [
"http://localhost:8080"
]
},
"postgres": {
"db": "postgres",
"user": "postgres",
"password": "mysecretpassword",
"host": "postgres",
"port": "5432"
}
}
I kill existing processing running on port 5432 and tried adding ports in the docker-compose file however it did not help.
I found there is help available on this topic and I tried most of those. But no luck yet.
Please help.