Description:
I am following the Docker development documentation:
https://wger.readthedocs.io/en/latest/development/docker.html
I am using the SQLite dev setup from dev/docker-compose.yml, with WGER_CODEPATH pointing to my local wger backend checkout.
When I start the dev environment and run wger bootstrap inside the web container, Django tries to use PostgreSQL instead of SQLite and fails because there is no db service in the SQLite dev compose setup.
Steps to reproduce:
-
Clone wger-docker.
-
Clone wger next to it.
-
Configure dev/.env, for example:
WGER_CODEPATH=C:\my_path\wger
-
Start the SQLite dev compose setup:
docker compose -f .\dev\docker-compose.yml up --watch
-
Enter the web container:
docker compose -f .\dev\docker-compose.yml exec web /bin/bash
-
Confirm the database env:
env | grep -E 'DJANGO_DB|DATABASE|POSTGRES|PS_'
The container has:
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
DJANGO_DB_ENGINE=django.db.backends.sqlite3
PS_DATABASE_URI=postgres://wger:wger@db:5432/wger
-
Run:
wger bootstrap
Expected behavior:
The SQLite dev setup should use:
DJANGO_DB_ENGINE=django.db.backends.sqlite3
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
and wger bootstrap should create/use /home/wger/src/database.sqlite.
Actual behavior:
wger bootstrap uses PostgreSQL and fails while resolving the db hostname:
django.db.utils.OperationalError: failed to resolve host 'db': [Errno -2] Name or service not known
Relevant traceback excerpt:
*** Using settings from env: settings.main
*** Database does not exist, creating one now
*** Using settings from env: settings.main
...
File "/home/wger/src/settings/main.py", line 65, in
DATABASES = {'default': env.db_url('PS_DATABASE_URI')}
...
django.db.utils.OperationalError: failed to resolve host 'db': [Errno -2] Name or service not known
Cause:
dev/docker-compose.yml loads these env files:
- ../config/prod.env
- ../config/dev.env
- ../config/dev-sqlite.env
config/prod.env sets:
PS_DATABASE_URI=postgres://wger:wger@db:5432/wger
config/dev-sqlite.env sets:
DJANGO_DB_ENGINE=django.db.backends.sqlite3
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
However, in settings/main.py, PS_DATABASE_URI is checked before DJANGO_DB_ENGINE:
if os.environ.get('PS_DATABASE_URI'):
DATABASES = {'default': env.db_url('PS_DATABASE_URI')}
elif os.environ.get('DJANGO_DB_ENGINE'):
DATABASES = {
'default': {
'ENGINE': env.str('DJANGO_DB_ENGINE'),
'NAME': env.str('DJANGO_DB_DATABASE'),
'USER': env.str('DJANGO_DB_USER'),
'PASSWORD': env.str('DJANGO_DB_PASSWORD'),
'HOST': env.str('DJANGO_DB_HOST'),
'PORT': env.int('DJANGO_DB_PORT'),
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': env.str('DJANGO_DB_DATABASE', '/home/wger/db/database.sqlite'),
}
}
So the PostgreSQL URL inherited from prod.env wins over the SQLite-specific env file.
Furthermore, simply unsetting PS_DATABASE_URI may expose a second SQLite config problem unless those optional fields of the elif condition get defaults or are omitted.
Environment:
- OS: Windows
- Shell: PowerShell
- Docker Compose setup:
dev/docker-compose.yml
- wger Docker dev mode: SQLite
Description:
I am following the Docker development documentation:
https://wger.readthedocs.io/en/latest/development/docker.html
I am using the SQLite dev setup from
dev/docker-compose.yml, withWGER_CODEPATHpointing to my local wger backend checkout.When I start the dev environment and run
wger bootstrapinside thewebcontainer, Django tries to use PostgreSQL instead of SQLite and fails because there is nodbservice in the SQLite dev compose setup.Steps to reproduce:
Clone
wger-docker.Clone
wgernext to it.Configure
dev/.env, for example:WGER_CODEPATH=C:\my_path\wger
Start the SQLite dev compose setup:
docker compose -f .\dev\docker-compose.yml up --watch
Enter the web container:
docker compose -f .\dev\docker-compose.yml exec web /bin/bash
Confirm the database env:
env | grep -E 'DJANGO_DB|DATABASE|POSTGRES|PS_'
The container has:
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
DJANGO_DB_ENGINE=django.db.backends.sqlite3
PS_DATABASE_URI=postgres://wger:wger@db:5432/wger
Run:
wger bootstrap
Expected behavior:
The SQLite dev setup should use:
DJANGO_DB_ENGINE=django.db.backends.sqlite3
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
and
wger bootstrapshould create/use/home/wger/src/database.sqlite.Actual behavior:
wger bootstrapuses PostgreSQL and fails while resolving thedbhostname:django.db.utils.OperationalError: failed to resolve host 'db': [Errno -2] Name or service not known
Relevant traceback excerpt:
*** Using settings from env: settings.main
*** Database does not exist, creating one now
*** Using settings from env: settings.main
...
File "/home/wger/src/settings/main.py", line 65, in
DATABASES = {'default': env.db_url('PS_DATABASE_URI')}
...
django.db.utils.OperationalError: failed to resolve host 'db': [Errno -2] Name or service not known
Cause:
dev/docker-compose.ymlloads these env files:config/prod.envsets:PS_DATABASE_URI=postgres://wger:wger@db:5432/wger
config/dev-sqlite.envsets:DJANGO_DB_ENGINE=django.db.backends.sqlite3
DJANGO_DB_DATABASE=/home/wger/src/database.sqlite
However, in
settings/main.py,PS_DATABASE_URIis checked beforeDJANGO_DB_ENGINE:So the PostgreSQL URL inherited from
prod.envwins over the SQLite-specific env file.Furthermore, simply unsetting PS_DATABASE_URI may expose a second SQLite config problem unless those optional fields of the elif condition get defaults or are omitted.
Environment:
dev/docker-compose.yml