尝试为我的 Docker 项目导入本地 Linux 服务器上的 Postgres/Postgis 数据库

问题描述 投票:0回答:1

还是新来的学生,正在努力为我的期末项目考试尽力而为。 我在一家公司实习,我的项目是使用lizmap和qgis。

我们可以找到所有已经 docker-compose 的项目:https://github.com/3liz/lizmap-docker-compose

我真正的问题是如何将我的 postgres/postgis 数据库放入我的项目(.env 和 docker-compose.yml)中,该项目位于公司本地 Linux 服务器中。

我可以毫无困难地使用 pgadmin 和 dbeaver 访问我的数据库:

jdbc:postgresql://10.7.99.122:5678/crypteo

我在 .env 和 docker-compose.yml 中尝试了很多东西:

LIZMAP_VERSION_TAG=3.6
LIZMAP_UID=1000
LIZMAP_GID=1000
LIZMAP_DIR=./lizmap
LIZMAP_PROJECTS=./lizmap/instances
QGIS_VERSION_TAG=3.28
QGIS_MAP_WORKERS=4
LIZMAP_PORT=8090
OWS_PORT=8091
POSTGIS_VERSION=13-3
POSTGIS_PORT=5432
POSTGIS_ALIAS=db.lizmap
POSTGRES_HOST=postgres
# ajout de la base de donnés Postgres avec DB, User et Password"
DATABASE_URL=jdbc:postgresql://crypteo:TgYETMWK%[email protected]:5678/crypteo
# POSTGRES_PASSWORD=postgres
# POSTGRES_LIZMAP_DB=crypteo
# POSTGRES_LIZMAP_USER=crypteo
# POSTGRES_LIZMAP_PASSWORD="TgYETMWK@xfP"
# POSTGRES_HOST="10.7.99.122"
# POSTGRES_PORT=5678

环境:

docker-compose.yml:

  postgis:
    image: 3liz/postgis:${POSTGIS_VERSION}
    volumes:
      - { type: volume, source: postgis_data, target: /var/lib/postgresql/data }
      - { type: bind, source: "${LIZMAP_DIR}/etc/postgres.init.d", target: /docker-entrypoint-initdb.d }
    environment:
      # ajout du serveur linux crypteo :
      DATABASE_URL: ${DATABASE_URL}
      # POSTGRES_HOST: ${POSTGRES_HOST}
      # POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      # POSTGRES_LIZMAP_DB: ${POSTGRES_LIZMAP_DB}
      # POSTGRES_LIZMAP_USER: ${POSTGRES_LIZMAP_USER}
      # POSTGRES_LIZMAP_PASSWORD: ${POSTGRES_LIZMAP_PASSWORD}
    ports:
      - ${POSTGIS_PORT}:5432
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d ${POSTGRES_LIZMAP_DB} -q || exit 1"]
      interval: 10s
      timeout: 5s
      start_period: 60s
    networks:
      default:
        aliases:
          - ${POSTGIS_ALIAS}

但这就是我最终在 docker compose up 时得到的结果:

  1. 当我使用当前注释掉的第一个没有“DATABASE_URL”的方法时:

.env

POSTGRES_PASSWORD=postgres
POSTGRES_LIZMAP_DB=crypteo
POSTGRES_LIZMAP_USER=crypteo
POSTGRES_LIZMAP_PASSWORD="TgYETMWK@xfP"
POSTGRES_HOST="10.7.99.122"
POSTGRES_PORT=5678

当我 docker 撰写时:

postgis-1  |
postgis-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgis-1  |
postgis-1  | 2024-01-23 16:05:59.090 UTC [1] LOG:  starting PostgreSQL 13.13 (Debian 13.13-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgis-1  | 2024-01-23 16:05:59.090 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgis-1  | 2024-01-23 16:05:59.090 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgis-1  | 2024-01-23 16:05:59.109 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgis-1  | 2024-01-23 16:05:59.126 UTC [32] LOG:  database system was shut down at 2024-01-23 16:00:03 UTC
postgis-1  | 2024-01-23 16:05:59.132 UTC [1] LOG:  database system is ready to accept connections
postgis-1  | 2024-01-23 16:06:39.131 UTC [72] FATAL:  database "crypteo" does not exist

当我使用第二种方法时:

.env :

DATABASE_URL=jdbc:postgresql://crypteo:TgYETMWK%[email protected]:5678/crypteo

当我 docker 撰写时:

postgis-1  |
postgis-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgis-1  |
postgis-1  | 2024-01-24 09:22:17.787 UTC [1] LOG:  starting PostgreSQL 13.13 (Debian 13.13-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgis-1  | 2024-01-24 09:22:17.790 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgis-1  | 2024-01-24 09:22:17.790 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgis-1  | 2024-01-24 09:22:17.815 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgis-1  | 2024-01-24 09:22:17.844 UTC [31] LOG:  database system was shut down at 2024-01-24 08:38:54 UTC
postgis-1  | 2024-01-24 09:22:17.859 UTC [1] LOG:  database system is ready to accept connections
postgis-1  | 2024-01-24 09:22:37.634 UTC [53] FATAL:  database "-q" does not exist

有人可以帮助我吗? :)

提前致谢

docker-compose postgis qgis
1个回答
0
投票

放弃健康检查,有必要吗? 你制作了数据库密码吗? 或者你有用户“crypteo”?拥有数据库“crypteo”的所有权限

© www.soinside.com 2019 - 2024. All rights reserved.