Running Kratos with Postgres

I’ve been looking at how would I setup postgres db instead of default sqlite provided in the quickstart example. Note that default quickstart worked for me so after that I ran:

docker-compose -f quickstart.yml -f quickstart-standalone.yml -f quickstart-postgres.yml up --build --force-recreate

I’m getting Unable to ping database, retrying. message. Any suggestions would be helpful. Below is full logs I have:

Creating network "kratos_default" with the default driver
Creating network "kratos_intranet" with the default driver
Creating kratos_kratos-selfservice-ui-node_1 ... done
Creating kratos_kratos-migrate_1             ... done
Creating kratos_postgresd_1                  ... done
Creating kratos_mailslurper_1                ... done
Creating kratos_kratos_1                     ... done
Attaching to kratos_kratos-selfservice-ui-node_1, kratos_kratos-migrate_1, kratos_postgresd_1, kratos_mailslurper_1, kratos_kratos_1
kratos-migrate_1              | time="2020-06-16T04:58:46Z" level=info msg="Config file loaded successfully." path=/etc/config/kratos/.kratos.yml
kratos-migrate_1              | time="2020-06-16T04:58:46Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:46Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:47Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:48Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:50Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:53Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:58:56Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T04:59:44Z" level=info msg="Config file loaded successfully." path=/etc/config/kratos/.kratos.yml
kratos_1                      | time="2020-06-16T04:59:44Z" level=warning msg="\n\nYOU ARE RUNNING ORY KRATOS IN DEV MODE.\nSECURITY IS DISABLED.\nDON'T DO THIS IN PRODUCTION!\n\n"
kratos_1                      | time="2020-06-16T04:59:44Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-selfservice-ui-node_1  | 
kratos-selfservice-ui-node_1  | > [email protected] serve /usr/src/app
kratos-selfservice-ui-node_1  | > node lib/index.js
kratos-selfservice-ui-node_1  | 
kratos_1                      | time="2020-06-16T04:59:45Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
mailslurper_1                 | time="2020-06-16T04:58:51Z" level=info msg="Starting MailSlurper Server v1.14.1" who=MailSlurper
kratos-selfservice-ui-node_1  | Listening on http://0.0.0.0:4455
kratos-migrate_1              | time="2020-06-16T04:59:02Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
mailslurper_1                 | time="2020-06-16T04:58:51Z" level=info msg="Connecting to database" who=MailSlurper
postgresd_1                   | The files belonging to this database system will be owned by user "postgres".
postgresd_1                   | This user must also own the server process.
postgresd_1                   | 
postgresd_1                   | The database cluster will be initialized with locale "en_US.utf8".
postgresd_1                   | The default database encoding has accordingly been set to "UTF8".
postgresd_1                   | The default text search configuration will be set to "english".
postgresd_1                   | 
postgresd_1                   | Data page checksums are disabled.
postgresd_1                   | 
kratos-migrate_1              | time="2020-06-16T04:59:15Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
postgresd_1                   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
mailslurper_1                 | time="2020-06-16T04:58:51Z" level=info msg="Creating database tables..." who=MailSlurper
kratos-migrate_1              | time="2020-06-16T04:59:22Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-selfservice-ui-node_1  | Security mode: cookie
kratos_1                      | time="2020-06-16T04:59:45Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
mailslurper_1                 | time="2020-06-16T04:59:01Z" level=info msg="Created tables successfully." who=MailSlurper
mailslurper_1                 | time="2020-06-16T04:59:01Z" level=info msg="Worker pool configured for 1000 workers" who="SMTP Server Pool"
kratos-migrate_1              | time="2020-06-16T04:59:39Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
postgresd_1                   | creating subdirectories ... ok
postgresd_1                   | selecting default max_connections ... 100
postgresd_1                   | selecting default shared_buffers ... 128MB
postgresd_1                   | selecting default timezone ... Etc/UTC
postgresd_1                   | selecting dynamic shared memory implementation ... posix
kratos_1                      | time="2020-06-16T04:59:46Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T04:59:48Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
mailslurper_1                 | ⇨ http server started on [::]:4437
mailslurper_1                 | time="2020-06-16T04:59:01Z" level=info msg="SMTP listener running on SSL 0.0.0.0:1025" who="SMTP Listener"
mailslurper_1                 | time="2020-06-16T04:59:01Z" level=info msg="1 receiver(s) listening" who="SMTP Listener"
mailslurper_1                 | time="2020-06-16T04:59:01Z" level=info msg="HTTP admin listener running on 0.0.0.0:4436" who=MailSlurper
mailslurper_1                 | ⇨ http server started on [::]:4436
postgresd_1                   | creating configuration files ... ok
postgresd_1                   | running bootstrap script ... ok
postgresd_1                   | performing post-bootstrap initialization ... ok
kratos_1                      | time="2020-06-16T04:59:50Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T04:59:55Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos-migrate_1              | time="2020-06-16T04:59:58Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T05:00:00Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T05:00:12Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
kratos_1                      | time="2020-06-16T05:00:22Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
xkratos_1                      | time="2020-06-16T05:00:35Z" level=warning msg="Unable to ping database, retrying." error="dial tcp: lookup postgresd on 127.0.0.11:53: no such host"
^CGracefully stopping... (press Ctrl+C again to force)

Looks like a bug in the docker-compose files, fixes/issues welcomed :slight_smile:

Just need to connect them to the same network in the docker-compose files. Fix here: https://github.com/ory/kratos/pull/522

I noticed running the docker-compose command that @anuveyatsu posted also starts sqlite, even though postgres seems to be the prefered store. Is sqlite needed for some other Kratos storage need?

Correction: actually sqlite is never actually running in a separate container but I guess embedded in the kratos image tagged as oryd/kratos:latest-sqlite. Just got confused when docker ps listed latest-sqlite.

Yes, SQLite is an embedded database.