Answer the question
In order to leave comments, you need to log in
Postgresql and using virtual environment and docker on the same project?
Locally setting up a project to work with docker and pipenv. Changed the database settings in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}
version: '3.7'
services:
web:
build: .
command: python /profi/manage.py runserver 0.0.0.0:8000
environment:
- SECRET_KEY=dy)zvq+sf07^^456t$$6+mv*tj6#5iwyo896-z!v=h^njl9^&@q
- DEBUG=1
volumes:
- .:/profi
ports:
- 8000:8000
depends_on:
- db
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/posgresql/data/
volumes:
postgres_data:
docker-compose up
then everything starts, only every time I need to create an admin. The database does not store data. Did you not finish something in volumes? pipenv shell
python manage.py runserver
that I get an errordjango.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known
Answer the question
In order to leave comments, you need to log in
As a result, the working configuration is this
docker-compose.yml
version: '3.7'
services:
web:
build: .
command: python /profi/manage.py runserver 0.0.0.0:8000
environment:
# DJANGO_SETTINGS_MODULE: "project.settings.development"
DEBUG: 1
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST: db
volumes:
- .:/profi
ports:
- "${HTTP_PORT:-8000}:8000"
depends_on:
- db
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/posgresql/data/
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_HOST: db
ports:
- "${DB_PORT:-5432}:5432"
volumes:
postgres_data:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('POSTGRES_DB', default='postgres'),
'USER': os.environ.get('POSTGRES_USER', default='postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', default='postgres'),
'HOST': os.environ.get('POSTGRES_HOST', default='localhost'),
'PORT': "5432"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question