Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: /usr/lib/libgdal.so.1: undefined symbol: OGR_F_GetFieldAsInteger64 While installing in Docker

Getting error while installing GeoDjango on docker with postgres db.

I'm completely new to docker and i'm setting up my project on docker. I don't know, is this error is regarding django or postgres.

Found this error

AttributeError: /usr/lib/libgdal.so.1: undefined symbol: OGR_F_GetFieldAsInteger64 While installing in Docker

docker-compose.yml

version: '3'
services:
        postgres:
                restart: always
                image: postgres:alpine
                volumes:
                        - ./postgres_gis/gis_db:/home/dev/gis_db.sql
                environment:
                        POSTGRES_USER: postgres
                        POSTGRES_PASSWORD: Dev@mishra123
                        POSTGRES_DB: gis_db
                expose:
                        - "5432"
        web:
                build: ./HomePage
                restart: always
                expose:
                        - "8000"
                volumes:
                        - ./HomePage:/home/dev/app/HomePage
                depends_on:
                        - postgres
                environment:
                        - DEBUG=1

web/Dockerfile

from python:3.6.2-slim
RUN groupadd dev && useradd -m -g dev -s /bin/bash dev
RUN echo "dev ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN mkdir -p /home/dev/app/HomePage
RUN chown -R dev:dev /home/dev/app
RUN chmod -R +x+r+w /home/dev/app
WORKDIR /home/dev/app/HomePage
RUN apt-get update && apt-get -y upgrade
COPY requirements.txt /home/dev/app/HomePage
RUN apt-get install -y python3-dev python3-pip
RUN apt-get install -y libpq-dev
RUN apt-get install -y binutils libproj-dev gdal-bin
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
USER dev
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

web/docker-entrypoint.sh

#!/bin/sh
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

docker-compose ps :

root@BlackCat:/home/dev/Project-EX/django-PR# docker-compose up      
Starting django-pr_postgres_1 ... done
Starting django-pr_web_1      ... done
Attaching to django-pr_postgres_1, django-pr_web_1
postgres_1  | 2019-12-12 16:34:43.907 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2019-12-12 16:34:43.908 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2019-12-12 16:34:44.099 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2019-12-12 16:34:44.672 UTC [18] LOG:  database system was shut down at 2019-12-11 18:45:45 UTC
postgres_1  | 2019-12-12 16:34:44.912 UTC [1] LOG:  database system is ready to accept connections
web_1       | Traceback (most recent call last):
web_1       |   File "manage.py", line 22, in <module>
web_1       |     execute_from_command_line(sys.argv)
web_1       |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
web_1       |     utility.execute()
web_1       |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
web_1       |     django.setup()
web_1       |   File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
web_1       |     apps.populate(settings.INSTALLED_APPS)
web_1       |   File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
web_1       |     app_config.import_models()
web_1       |   File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
web_1       |     self.models_module = import_module(models_module_name)
web_1       |   File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
web_1       |     return _bootstrap._gcd_import(name[level:], package, 
web_1       |     func = self.__getitem__(name)
web_1       |   File "/usr/local/lib/python3.6/ctypes/__init__.py", line 366, in __getitem__
web_1       |     func = self._FuncPtr((name_or_ordinal, self))
web_1       | AttributeError: /usr/lib/libgdal.so.1: undefined symbol: OGR_F_GetFieldAsInteger64
web_1       | Watching for file changes with StatReloader
like image 843
Dev Avatar asked Dec 12 '19 17:12

Dev


1 Answers

The problem you are encountering is that your version of GDAL is too old. Your Dockerfile is built on python:3.6.2-slim, which is based off Debian Jessie, and installs gdal version 1.10.1. The OGR_F_GetFieldAsInteger64 variable was introduced in v. 2.0.0

According to the GDAL package page at debian.org, you need a newer version of Debian (stretch, buster, bullseye will all work). As such, I would recommend that you change your Dockerfile to use python:3.8.0-slim-buster or newer. Please check the hub.docker.com python page for more information

Also, as mentioned in the comments, your Dockerfile should only have one of CMD or ENTRYPOINT, but not both. Since your entrypoint.sh does what CMD does and more, I'd just remove CMD and stick with ENTRYPOINT

Disclosure: I work for EnterpriseDB (EDB)

like image 73
richyen Avatar answered Oct 20 '22 15:10

richyen