Answer the question
In order to leave comments, you need to log in
Python-Django-Docker, how to connect to docker via localhost?
Good afternoon, in the docker there is a postgresql database with forwarded 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
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'provizorro',
'USER': 'provizorro',
'PASSWORD': 'Provizorro666',
'HOST': 'postgres',
'PORT': 5432,
}
}
Answer the question
In order to leave comments, you need to log in
docker-compose.yml:
web:
...
links:
- postgres
env_file: .env
...
DB_HOST=postgres
DB_PORT=5432
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
...
'HOST': os.environ.get('DB_HOST'),
'PORT': os.environ.get('DB_PORT'),
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question