question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker configured with postgres uses sqlite3

See original GitHub issue

With the docker image ghcr.io/linuxserver/babybuddy, usage of postgres as database does not work by setting the environment variables, babybuddy still writes data to the sqlite3 database.

I’ve previously set up babybuddy with postgres using docker-compose:

version: "2.1"
services:
  babybuddy:
    image: babybuddy/babybuddy
    environment:
      - TZ=UTC
      - DB_ENGINE=django.db.backends.postgresql
      - DB_PASSWORD=password
      - DB_HOST=db
      - DB_NAME=postgres
      - DB_PORT=5432
      - DB_USER=postgres
      - DJANGO_SETTINGS_MODULE=babybuddy.settings.docker
      - SECRET_KEY=1234
      - ALLOWED_HOSTS=*
    ports:
      - 8000:8000
    restart: unless-stopped
    command: bash -c 'sleep 5 && python manage.py migrate --noinput && python manage.py createcachetable && gunicorn babybuddy.wsgi -b :8000 --log-level=info'
  db:
    image: postgres:12
    environment:
      - PGDATA=/db-data
      - POSTGRES_PASSWORD=password
    volumes:
      - data:/db-data
volumes:
  data:

Now I’ve changed that to use the new image from linuxservers:

version: "2.1"
services:
  babybuddy:
    image: ghcr.io/linuxserver/babybuddy
    environment:
      - TZ=UTC
      - DB_ENGINE=django.db.backends.postgresql
      - DB_PASSWORD=password
      - DB_HOST=db
      - DB_NAME=postgres
      - DB_PORT=5432
      - DB_USER=postgres
    ports:
      - 8000:8000
    restart: unless-stopped
  db:
    image: postgres:12
    environment:
      - PGDATA=/db-data
      - POSTGRES_PASSWORD=password
    volumes:
      - data:/db-data
volumes:
  data:

I’ve observed that nothing is written to the postgres database:

$ docker-compose exec db /bin/bash
root@42a8ea9dd26d:/# psql -U postgres
psql (12.7 (Debian 12.7-1.pgdg100+1))
Type "help" for help.

postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \dt
Did not find any relations.
postgres=#

However, I’ve noticed that whenever I log on, the timestamp of the sqlite3 file /config/data/db.sqlite3 is updated.

Logs (nothing interesting):

db_1         |
db_1         | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1         |
babybuddy    | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
babybuddy    | [s6-init] ensuring user provided files have correct perms...exited 0.
babybuddy    | [fix-attrs.d] applying ownership & permissions fixes...
babybuddy    | [fix-attrs.d] done.
babybuddy    | [cont-init.d] executing container initialization scripts...
babybuddy    | [cont-init.d] 01-envfile: executing...
babybuddy    | [cont-init.d] 01-envfile: exited 0.
babybuddy    | [cont-init.d] 10-adduser: executing...
db_1         | 2021-08-05 18:43:49.005 UTC [1] LOG:  starting PostgreSQL 12.7 (Debian 12.7-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1         | 2021-08-05 18:43:49.006 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1         | 2021-08-05 18:43:49.007 UTC [1] LOG:  listening on IPv6 address "::", port 5432
babybuddy    | usermod: no changes
babybuddy    |
babybuddy    | -------------------------------------
babybuddy    |           _         ()
babybuddy    |          | |  ___   _    __
babybuddy    |          | | / __| | |  /  \
babybuddy    |          | | \__ \ | | | () |
babybuddy    |          |_| |___/ |_|  \__/
babybuddy    |
babybuddy    |
babybuddy    | Brought to you by linuxserver.io
babybuddy    | -------------------------------------
babybuddy    |
babybuddy    | To support the app dev(s) visit:
babybuddy    | BabyBuddy: https://github.com/sponsors/cdubz
db_1         | 2021-08-05 18:43:49.020 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
babybuddy    |
babybuddy    | To support LSIO projects visit:
babybuddy    | https://www.linuxserver.io/donate/
babybuddy    | -------------------------------------
babybuddy    | GID/UID
babybuddy    | -------------------------------------
babybuddy    |
babybuddy    | User uid:    911
babybuddy    | User gid:    911
babybuddy    | -------------------------------------
babybuddy    |
babybuddy    | [cont-init.d] 10-adduser: exited 0.
babybuddy    | [cont-init.d] 30-config: executing...
db_1         | 2021-08-05 18:43:49.079 UTC [25] LOG:  database system was shut down at 2021-08-05 18:27:03 UTC
db_1         | 2021-08-05 18:43:49.104 UTC [1] LOG:  database system is ready to accept connections
babybuddy    | Operations to perform:
babybuddy    |   Apply all migrations: admin, auth, authtoken, axes, babybuddy, contenttypes, core, easy_thumbnails, sessions
babybuddy    | Running migrations:
babybuddy    |   No migrations to apply.
babybuddy    |   Your models in app(s): 'babybuddy' have changes that are not yet reflected in a migration, and so won't be applied.
babybuddy    |   Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
babybuddy    | Cache table 'cache_default' already exists.
babybuddy    | [cont-init.d] 30-config: exited 0.
babybuddy    | [cont-init.d] 90-custom-folders: executing...
babybuddy    | [cont-init.d] 90-custom-folders: exited 0.
babybuddy    | [cont-init.d] 99-custom-files: executing...
babybuddy    | [custom-init] no custom files found exiting...
babybuddy    | [cont-init.d] 99-custom-files: exited 0.
babybuddy    | [cont-init.d] done.
babybuddy    | [services.d] starting services
babybuddy    | [services.d] done.
babybuddy    | [2021-08-05 18:43:53 +0000] [284] [INFO] Starting gunicorn 20.1.0
babybuddy    | [2021-08-05 18:43:53 +0000] [284] [INFO] Listening at: http://0.0.0.0:8000 (284)
babybuddy    | [2021-08-05 18:43:53 +0000] [284] [INFO] Using worker: gthread
babybuddy    | [2021-08-05 18:43:53 +0000] [297] [INFO] Booting worker with pid: 297
babybuddy    | [2021-08-05 18:43:53 +0000] [298] [INFO] Booting worker with pid: 298

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Aohzancommented, Aug 6, 2021

indeed, thanks for the tip

1reaction
cdubzcommented, Aug 5, 2021

@BenjaminHae thanks for raising. It looks like this happens because the LSIO image run file uses base.py for settings and that base settings file does not respect the DB_* environment variables. Previously this would’ve used the docker.py settings.

I think it would make sense to modify base.py to use those environment variables when present, falling back on the current SQLite based config. We could probably also get rid of the Docker specific settings file now as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django & Docker - SQLite, MySql, and PostgreSQL samples
Free samples that use different combinations between Django, Docker, and DB layer: SQLite, MySql, PostgreSQL.
Read more >
Airflow via docker-compose keeps trying to access sqlite ...
I point to the Postgres instance everywhere (deemed) possible through AIRFLOW__CORE__SQL_ALCHEMY_CONN , and even AIRFLOW_CONN_METADATA_DB . A ...
Read more >
Switch existing setup from sqlite3 to remote mysql · Issue #1037
I tried to migrate my existing test setup from sqlite3 to mysql by adding the necessary variables to mailu docker-compose env file, ...
Read more >
How to setup Postgresql as a replacement to default sqlite3 in ...
ini file to replace sqlite with postgres and created Grafana Docker image from it. Created a AKS Kubernetes deployment with GF_DATABASE_URL to ...
Read more >
Django & Docker - SQLite, MySql, and PostgreSQL samples
Free samples that use different combinations between Django, Docker, and DB layer: SQLite, MySql, PostgreSQL.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found