Search code examples
postgresqldocker-composepostgis

Docker-compose with postgres with geography postgis not working


I am using a docker-compose container that runs a flask app. Within this container a postgres container is launched with the Postgis extension (the mdillon/postgis image). Everything runs fine but a single Postgis extension (Geography) does not work, which I can not explain.

My docker-compose.yml:

version: '3.7'
services:
  flask:
    build: .
    entrypoint:
      - flask
      - run
      - --host=0.0.0.0
    environment:
      FLASK_DEBUG: 1
      FLASK_APP: app.py
    ports:
      - '5000:5000'
    volumes:
      - './app:/app'
    networks:
      - db_net
  db:
    image: mdillon/postgis
    networks:
      - db_net

networks:
  db_net:

After running sudo docker-compose up --build it creates two containers:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                     NAMES
1836d3d15765        img_flask         "flask run --host=0.…"   9 minutes ago       Up 9 minutes        80/tcp, 443/tcp, 0.0.0.0:5000->5000/tcp   img_flask_1
b25752af45ad        mdillon/postgis     "docker-entrypoint.s…"   13 minutes ago      Up 13 minutes       5432/tcp                                  img_db_1

When opening the flask app or db logs it claims the following:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) type "geography" does not exist
LINE 7:  geom geography(POINT,4326)

Checking postgis is correct and reinstalling it within the DB does not solve it. The packages are as follows:

                                            List of installed extensions
          Name          | Version |   Schema   |                             Description                             
------------------------+---------+------------+---------------------------------------------------------------------
 fuzzystrmatch          | 1.1     | public     | determine similarities and distance between strings
 plpgsql                | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis                | 2.5.0   | public     | PostGIS geometry, geography, and raster spatial types and functions
 postgis_tiger_geocoder | 2.5.0   | tiger      | PostGIS tiger geocoder and reverse geocoder
 postgis_topology       | 2.5.0   | topology   | PostGIS topology spatial types and functions
(5 rows)

Summarising, my containers work fine and Postgis is well installed. But there is a problem when a query requests the Geography function. Is there anyone that can give advice on how to solve this? Thanks!


Solution

  • Fixed, Accidentally working in a different db. @Jeremy thanks!