Python-Django-Docker, how to connect to Docker on localhost?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
30 views
Good day, Docker is a database postgresql prekinuti data
postgres: image: postgres ports: - "5001:5432" environment: POSTGRES_DB: provizorro POSTGRES_USER: provizorro POSTGRES_PASSWORD: Provizorro666 volumes: - /home/sergey/Projects/data-pg:/var/lib/postgresql/data

From Jangi connect to the database, here's how
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'provizorro', 'USER': 'provizorro', 'PASSWORD': 'Provizorro666', 'HOST': 'postgres' 'PORT': 5432, } }

How to configure the container, so you can connect to the local host?
by | 30 views

1 Answer

0 like 0 dislike
docker-compose.yml:
web: ... links: - postgres env_file: .env


.env
... DB_HOST=postgres DB_PORT=5432


then
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', ... 'HOST': os.environ.get('DB_HOST'), 'PORT': os.environ.get('DB_PORT'), } }
by

Related questions

110,608 questions
257,186 answers
0 comments
28,052 users