使用 docker 创建扩展 postgis 错误。已安装所有库

Create extension postgis error with docker. All libs installed

我在 postgresql 和 Docker 中创建扩展 postgis 时遇到问题。我已经阅读了很多 post 和教程,但我都失败了 :) 我正在研究 WSL :

# uname -a
Linux 6019b3c71dfc 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux

# psql -U user -d database -h db
psql (11.14 (Debian 11.14-0+deb10u1), server 10.18)
Type "help" for help.

massifs=# CREATE EXTENSION postgis;
ERROR:  could not open extension control file "/usr/local/share/postgresql/extension/postgis.control": No such file or directory

所以,我找到了 postgis.control 文件:

#  find /usr -name postgis.control
/usr/share/postgresql/11/extension/postgis.control

并将其复制(并根据需要更改权限)到正确的文件夹中:cp /usr/share/postgresql/11/extension/postgis.control /usr/local/share/postgresql/extension

但是错误是一样的:(

我已经安装了所有需要的库:

# dpkg -l | grep postgis
ii  postgis                              2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL
ii  postgis-doc                          2.5.1+dfsg-1                 all          Geographic objects support for PostgreSQL -- documentation
ii  postgis-gui                          2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL -- GUI programs
ii  postgresql-11-postgis-2.5            2.5.1+dfsg-1                 amd64        Geographic objects support for PostgreSQL 11
ii  postgresql-11-postgis-2.5-scripts    2.5.1+dfsg-1                 all          Geographic objects support for PostgreSQL 11 -- SQL scripts

同样的错误:(

我的docker-compose.yaml:

#./dj/docker-compose.yml
version: '3.7'

services:
  web:
    env_file:
      - ./env/django.env
    build:
         context: ./myproject
         dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./myproject:/opt/myproject
    ports:
      - "8050:8000"
    depends_on:
      - db
    restart: always

  db:
    env_file:
      - ./env/postgresql.env
    image: postgis/postgis
    #image: postgres:10-alpine
    container_name: postgres_container_myproject
    hostname: db
    volumes:
      - /var/lib/postgresql/data-myproject:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: always

  pgadmin:
    env_file:
      - ./env/pgadmin.env
    image: dpage/pgadmin4
    container_name: pgadmin_container_myproject
    ports:
      - "8059:80"
    volumes:
      - /var/lib/pgadmin/data:/var/lib/pgadmin/data
    links:
      - "db:pgsql-server"
    restart: always
    logging:
      driver: none

volumes:
  pgadmin_data:
  postgres_data:
    driver: local

你有什么想法吗?

请注意,您正在连接到错误的服务器错误版本的服务器:

psql (11.14 (Debian 11.14-0+deb10u1), server 10.18)

报告了 10 (10.18) 的服务器版本,它肯定不是由包 postgresql-11-postgis-2.5 安装的(即版本 11).

我假设您正在连接到另一个未安装正确软件包的 machine/container(不是 localhost)。

我一直在用postgis/docker-postgis for if you want to check how they are doing it the Dockerfile是个好地方