How to connect ODK-X with pgadmin

Hi all,

I have a hard time try to understand the docker structure of ODK X and i don´t be able to see how to connect the db container with pgadmin to manage the data and add additional features.

Any idea, document to follow, TKS

1 Like

The networks are controlled in the docker-compose file. For security reasons the default setup of sync-endpoint establishes an internal only network called ‘db-network’ that only containers assigned to that network can access. To give other containers access you have to add them to the ‘db-network’. If you want to access the database externally you will need to expose the ports.

The docker compose file setups all the networking:

1 Like

In case of use to anyone else, these are the changes I made to include phppgadmin. First add a phppgadmin block to docker-compose.yml

phppgadmin:
    image: dockage/phppgadmin:latest
    deploy:
      replicas: 1
    environment:
      - PHP_PG_ADMIN_SERVER_DESC=ODK-X Postgres
      - PHP_PG_ADMIN_SERVER_HOST=db
      - PHP_PG_ADMIN_SERVER_PORT=5432
      - PHP_PG_ADMIN_SERVER_DEFAULT_DB=postgres
    networks:
      - db-network

Make sure to specify the db-network as mentioned above so that phppgadmin can communicate with the postgres database. By setting the PHP_PG_ADMIN_SERVER_HOST=db the service should be able to connect directly to the database across the network (assuming your postgres service is called ‘db’, if not change the environment variable to match).

Then if you want to expose the service on your webserver you can add a location block to config/nginx/sync-endpoint-locations.conf, e.g

location /phppgadmin/ {
	proxy_set_header Host $host;
	proxy_pass http://phppgadmin/;
}

Note, this also assumes nginx and phppgadmin are on the same network (e.g. both access db-network, or perhaps more securely create a new network and add to both). Alternatively you could just expose the service to another port on your system to access like in phpldapadmin and ignore the nginx location block.

I also tried pgadmin4 (which works in a similar way), but personally I’m not a huge fan. Example docker-compose block for reference:

pgadmin4:
    image: dpage/pgadmin4
    volumes:
      - pgadmin-vol:/root/.pgadmin
    networks:
      - db-network
    environment:
      - PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
      - PGADMIN_DEFAULT_PASSWORD=admin

and sync-endpoint-locations.conf block:

location /pgadmin4/ {
	proxy_set_header X-Script-Name /pgadmin4;
	proxy_set_header Host $host;
	proxy_pass http://pgadmin4/;
	proxy_redirect off;
}
1 Like