简体   繁体   English

无法从在另一个 docker continer 中运行的 Geoserver 连接到在 docker 中运行的 Postgis

[英]Can't connect to Postgis running in docker from Geoserver running in another docker continer

I used kartoza's docker images for Geoserver and Postgis and started them in two docker containers using the provided docker-compose.yml:我将kartoza 的docker 图像用于 Geoserver 和 Postgis,并使用提供的 docker-compose.yml 在两个 docker 容器中启动它们:

version: '2.1'

volumes:
   geoserver-data:
   geo-db-data:

services:
   db:
      image: kartoza/postgis:12.0
      volumes:
         - geo-db-data:/var/lib/postgresql
      ports:
        - "25434:5432"
      env_file:
      - docker-env/db.env
      restart: on-failure
      healthcheck:
        test: "exit 0"

   geoserver:
      image: kartoza/geoserver:2.17.0
      volumes:
        - geoserver-data:/opt/geoserver/data_dir
      ports:
        - "8600:8080"
      restart: on-failure
      env_file:
        - docker-env/geoserver.env
      depends_on:
        db:
          condition: service_healthy
      healthcheck:
        test: curl --fail -s http://localhost:8080/ || exit 1
        interval: 1m30s
        timeout: 10s
        retries: 3

The referenced.env files are:引用的 .env 文件是:

db.env数据库环境

POSTGRES_DB=gis,gwc
POSTGRES_USER=docker
POSTGRES_PASS=docker
ALLOW_IP_RANGE=0.0.0.0/0

geoserver.env地理服务器.env

GEOSERVER_DATA_DIR=/opt/geoserver/data_dir
ENABLE_JSONP=true
MAX_FILTER_RULES=20
OPTIMIZE_LINE_WIDTH=false
FOOTPRINTS_DATA_DIR=/opt/footprints_dir
GEOWEBCACHE_CACHE_DIR=/opt/geoserver/data_dir/gwc
GEOSERVER_ADMIN_PASSWORD=myawesomegeoserver
INITIAL_MEMORY=2G
MAXIMUM_MEMORY=4G
XFRAME_OPTIONS='false'
STABLE_EXTENSIONS=''
SAMPLE_DATA=false
GEOSERVER_CSRF_DISABLED=true

docker-compose up brings both containers up and running with no errors giving them names backend_db_1 (Postgis) and backend_geoserver_1 (Geoserver). docker-compose up启动并运行两个容器,没有错误给它们命名backend_db_1 (Postgis) 和backend_geoserver_1 (Geoserver)。 I can access Geoserver running in backend_geoserver_1 under http://localhost:8600/geoserver/ as expected.我可以按预期访问在backend_geoserver_1 http://localhost:8600/geoserver/下的 backend_geoserver_1 中运行的 Geoserver。 I can connect an external, AWS-based Postgis as a data store to my docker-based Geoserver instance without any problems.我可以将一个外部的、基于 AWS 的 Postgis 作为数据存储连接到我的基于 docker 的 Geoserver 实例,没有任何问题。 I can also access the Postgis running in the docker container backend_db_1 from PgAdmin, with psql from the command line and from the Webstorm IDE.我还可以从 PgAdmin 访问在 docker 容器 backend_db_1 中运行的backend_db_1 ,从命令行和 Webstorm IDE 使用psql

However, if I try to use my Postgis running in backend_db_1 as a data store for my Geoserver running in backend_geoserver_1 , I get the following error:但是,如果我尝试使用在 backend_db_1 中运行的backend_db_1作为在backend_geoserver_1中运行的 Geoserver 的数据存储,我会收到以下错误:

> Error creating data store, check the parameters. Error message: Unable
> to obtain connection: Cannot create PoolableConnectionFactory
> (Connection to localhost:25434 refused. Check that the hostname and
> port are correct and that the postmaster is accepting TCP/IP
> connections.)

So, my Geoserver in backend_geoserver_1 can connect to Postgis on AWS, but not to the one running in another docker container on the same localhost.因此,我在 backend_geoserver_1 中的地理服务器可以连接到 AWS 上的backend_geoserver_1 ,但不能连接到在同一本地主机上的另一个 docker 容器中运行的服务器。 The Postgis in backend_db_1 in its turn can be accessed from many other local apps and tools, but not from Geoserver running in a docker container. backend_db_1 中的backend_db_1又可以从许多其他本地应用程序和工具访问,但不能从运行在 docker 容器中的 Geoserver 访问。

Any ideas what I am missing?有什么想法我想念的吗? Thanks!谢谢!

just add the network_mode in YAML in db and geoserver and set it to host只需在 db 和 geoserver 中的 YAML 中添加network_mode并将其设置为host

network_mode: host

note that this will ignore the expose option and will use the host.network an containers.network请注意,这将忽略 expose 选项并将使用 host.network 和 containers.network

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM