Using a custom db

Hi,

It seems we need to add network_mode: "host" in the docker-compose.yml to be able to use a custom postgres server on the host.

service:
    network_mode: "host"
    build:
      context: .
      dockerfile: service.dockerfile

I don't know if that's a safeguard not to add it by default.

Also can I just remove the "postgres" part in the docker-compose file when using a custom db?

Hi again,

Now this change seems to create other problems, as nginx cannot start properly:

2022/05/20 04:20:16 [emerg] 14#14: host not found in upstream "enketo" in /etc/nginx/conf.d/odk.conf:23
nginx: [emerg] host not found in upstream "enketo" in /etc/nginx/conf.d/odk.conf:23

The initial need for network_mode: "host" was that

sudo docker compose exec service odk-cmd --email example@example.com user-create

was giving an error:

ConnectionError: connect ECONNREFUSED 127.0.0.1:5432
    at Object.createConnection (/usr/odk/node_modules/slonik/dist/src/factories/createConnection.js:54:23)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

from inside the service container, trying to connect with psql:

sudo docker compose exec service /bin/bash
psql -h 127.0.1.1 -p 5432 -U user db

gave

psql: connection to server at "127.0.1.1", port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?

Installing net-tools to use route makes me confident in 127.0.1.1 being the right IP adress for the host.
nmap shows the port being state: closed

What should be done to use a custom postgres database if network_mode: host is not the solution?

So my question is:

it seems that when using the custom db, even when putting the right host in the config, service cannot access this postgres db as the port is closed in the container, how to do?

While ping host.docker.internal resolves to 127.0.1.1, this is not the address to use, but rather the IP address of the docker0 interface in the host.

The only changes you have to make to use a custom DB are outlined at https://docs.getodk.org/central-install-digital-ocean/#using-a-custom-database-server.

You should not have have to change network_mode. How did you determine that you needed to make that change to begin with?

You can remove the postgres section of docker-compose.yml, but it's not necessary because the postgres container doesn't use a lot of resources and the edits may introduce merge conflicts in the future.