Я столкнулся с некоторой проблемой при подключении нескольких баз данных в контейнере. на Unix доменном сокете "/var/run/postgresql/.s.PGSQL.5432"?
Итак, здесь я подключаю свои 2 веб-сервера (контейнера) к один контейнер путем разделения баз данных. Здесь мой web_1 контейнер работает нормально, но я столкнулся с проблемой с cloud_1.
ОС: Ubuntu 19.04
Docker версия: 19.03.3
Django настройка базы данных:
DATABASES = {
#'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#},
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'cloud_app',
'user': 'postgres',
'host':'db',
'password':'My@password',
'port':5432,
},
}
docker -compose.yml
version: '3'
services:
db:
restart: always
image: kartoza/postgis
volumes:
- ./postgres_gis/gis_db:/home/dev/gis_db.sql
- ./postgres_gis/cloud_storage:/home/dev/cloud_storage
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: Dev@mishra123
POSTGRES_DB: gis_db,cloud_storage
expose:
- "5432"
web:
build: ./HomePage
restart: always
expose:
- "8000"
volumes:
- ./HomePage:/home/dev/app/HomePage
ports:
- "8000:8000"
depends_on:
- db
environment:
DEBUG: 1
ENV: "DEV"
cloud:
build: ./CloudApp
restart: always
expose:
- "8000"
volumes:
- ./CloudApp:/home/dev/app/CloudApp
ports:
- "8003:8000"
depends_on:
- db
environment:
DEBUG: 1
ENV: "DEV"
Ошибка: -
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 56, in has_table
web_1 | return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 260, in cursor
web_1 | return self._cursor()
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 236, in _cursor
web_1 | self.ensure_connection()
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
web_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 197, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 126, 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 "db" (172.19.0.2) and accepting
web_1 | TCP/IP connections on port 5432?
web_1 |
cloud_1 | Traceback (most recent call last):
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 197, in connect
cloud_1 | self.connection = self.get_new_connection(conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
cloud_1 | connection = Database.connect(**conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 126, in connect
cloud_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cloud_1 | psycopg2.OperationalError: could not connect to server: No such file or directory
cloud_1 | Is the server running locally and accepting
cloud_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
cloud_1 |
cloud_1 |
cloud_1 | The above exception was the direct cause of the following exception:
cloud_1 |
cloud_1 | Traceback (most recent call last):
cloud_1 | File "/home/dev/app/CloudApp/manage.py", line 24, in <module>
cloud_1 | main()
cloud_1 | File "/home/dev/app/CloudApp/manage.py", line 20, in main
cloud_1 | execute_from_command_line(sys.argv)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
cloud_1 | utility.execute()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
cloud_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 328, in run_from_argv
cloud_1 | self.execute(*args, **cmd_options)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 369, in execute
cloud_1 | output = self.handle(*args, **options)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 83, in wrapped
cloud_1 | res = handle_func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 84, in handle
cloud_1 | connection.prepare_database()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 25, in prepare_database
cloud_1 | with self.cursor() as cursor:
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 260, in cursor
cloud_1 | return self._cursor()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 236, in _cursor
cloud_1 | self.ensure_connection()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
cloud_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 197, in connect
cloud_1 | self.connection = self.get_new_connection(conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
cloud_1 | connection = Database.connect(**conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 126, in connect
cloud_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cloud_1 | django.db.utils.OperationalError: could not connect to server: No such file or directory
cloud_1 | Is the server running locally and accepting
cloud_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
cloud_1 |
db_1 | List of databases
db_1 | Name | Owner | Encoding | Collate | Ctype | Access privileges
db_1 | ---------------+----------+----------+---------+---------+-----------------------
db_1 | cloud_storage | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
db_1 | gis_db | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
db_1 | postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
db_1 | template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
db_1 | | | | | | postgres=CTc/postgres
db_1 | template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
db_1 | | | | | | postgres=CTc/postgres
db_1 | (5 rows)
db_1 |
db_1 | 2020-01-29 17:43:40.099 UTC [12] LOG: received smart shutdown request
db_1 | 2020-01-29 17:43:40.159 UTC [12] LOG: background worker "logical replication launcher" (PID 77) exited with exit code 1
db_1 | 2020-01-29 17:43:40.160 UTC [72] LOG: shutting down
db_1 | 2020-01-29 17:43:40.442 UTC [12] LOG: database system is shut down
db_1 | Postgres initialisation process completed .... restarting in foreground
db_1 | 2020-01-29 17:43:41.190 UTC [205] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-01-29 17:43:41.190 UTC [205] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-01-29 17:43:41.190 UTC [205] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-01-29 17:43:41.275 UTC [205] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-01-29 17:43:41.433 UTC [207] LOG: database system was shut down at 2020-01-29 17:43:40 UTC
db_1 | 2020-01-29 17:43:41.470 UTC [205] LOG: database system is ready to accept connections
web_1 | Operations to perform:
web_1 | Apply all migrations: accounts, admin, auth, authtoken, contenttypes, group_management, locations, sessions
web_1 | Running migrations:
web_1 | No migrations to apply.
cloud_1 | Exception in thread django-main-thread:
cloud_1 | Traceback (most recent call last):
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 197, in connect
cloud_1 | self.connection = self.get_new_connection(conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
cloud_1 | connection = Database.connect(**conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 126, in connect
cloud_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cloud_1 | psycopg2.OperationalError: could not connect to server: No such file or directory
cloud_1 | Is the server running locally and accepting
cloud_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
cloud_1 |
cloud_1 |
cloud_1 | The above exception was the direct cause of the following exception:
cloud_1 |
cloud_1 | Traceback (most recent call last):
cloud_1 | File "/usr/local/lib/python3.9/threading.py", line 944, in _bootstrap_inner
cloud_1 | self.run()
cloud_1 | File "/usr/local/lib/python3.9/threading.py", line 882, in run
cloud_1 | self._target(*self._args, **self._kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
cloud_1 | fn(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
cloud_1 | self.check_migrations()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in check_migrations
cloud_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 18, in __init__
cloud_1 | self.loader = MigrationLoader(self.connection)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 49, in __init__
cloud_1 | self.build_graph()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 212, in build_graph
cloud_1 | self.applied_migrations = recorder.applied_migrations()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations
cloud_1 | if self.has_table():
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 56, in has_table
cloud_1 | return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 260, in cursor
cloud_1 | return self._cursor()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 236, in _cursor
cloud_1 | self.ensure_connection()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
cloud_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
cloud_1 | self.connect()
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 197, in connect
cloud_1 | self.connection = self.get_new_connection(conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
cloud_1 | return func(*args, **kwargs)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
cloud_1 | connection = Database.connect(**conn_params)
cloud_1 | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 126, in connect
cloud_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cloud_1 | django.db.utils.OperationalError: could not connect to server: No such file or directory
cloud_1 | Is the server running locally and accepting
cloud_1 | connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
cloud_1 |
web_1 | Watching for file changes with StatReloader
web_1 | [29/Jan/2020 17:43:52] "GET /api/users/ HTTP/1.1" 200 14544
web_1 | Not Found: /favicon.ico
web_1 | [29/Jan/2020 17:43:53] "GET /favicon.ico HTTP/1.1" 404 2649