Is it normal that the database isn't accessible right away? - eviltoast

Hello all!

A have a huge hassle setting this marvelous thing up, and finally, it seems, all my:

thread ‘main’ panicked at 'Error connecting to postgres://lemmy:PASSWORD@postgres:5432/lemmy: FATAL: password authentication failed for user “lemmy”

vanished as I, it seems, got lemmy to connect to my postgres database…

When I start up though, I still get one error and I would like to know if it’s “normal” (some race condition maybe) or not at all and I falsely believe it all is OK…

Thanks in beforehand!

Here is the output when I start it all up:

fediverse@fediverse-OptiPlex-3060:/media/fediverse/Storage/lemmy$ docker-compose up Creating network “lemmy_default” with the default driver Creating lemmy_postgres_1 … done Creating lemmy_pictrs_1 … done Creating lemmy_postfix_1 … done Creating lemmy_lemmy_1 … done Creating lemmy_lemmy-ui_1 … done Creating lemmy_proxy_1 … done Attaching to lemmy_postgres_1, lemmy_postfix_1, lemmy_pictrs_1, lemmy_lemmy_1, lemmy_lemmy-ui_1, lemmy_proxy_1 lemmy_1 | thread ‘main’ panicked at 'Error connecting to postgres://lemmy:PASSWORD@postgres:5432/lemmy: could not connect to server: Connection refused lemmy_1 | Is the server running on host “postgres” (172.18.0.2) and accepting lemmy_1 | TCP/IP connections on port 5432? lemmy_1 | ', crates/db_schema/src/utils.rs:161:56 lemmy_1 | note: run with RUST_BACKTRACE=1 environment variable to display a backtrace lemmy-ui_1 | Inferno is in development mode. postgres_1 | postgres_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization postgres_1 | proxy_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration proxy_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/

  • Max-P@lemmy.max-p.me
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    It is possible - Docker only checks by default that the service has started up, not that it’s fully up and running so there can be brief period where PostgreSQL is running but hasn’t finished loading up just yet.

    The dependencies mostly help make sure that the postgres container exists so that things that only check the name-> IP mapping exists once on startup don’t fail to start. NGINX will yell at you if you try to start it before lemmy and lemmy-ui exists, but once it’s started it doesn’t care if it’s not responding to requests yet it’ll just try every request as normal.

    • Valmond@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Thank you very much!

      I still haven’t proved it all works, I get a JSON error when trying to enter the admin credentials, but one step at a time!

      Cheers

      • Geronimo Wenja@agora.nop.chat
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 year ago

        If you want to avoid it happening, you can add a healthcheck to the postures service. Have a look online for docker healthchecks for postgres. That’ll let it ensure it’s actually ready to receive queries before dependencies start up.