简体   繁体   English

在docker容器中运行的Solr未连接到PostgreSQL数据库

[英]Solr running inside docker container is not connecting to PostgreSQL database

I have PostgreSQL and Solr, in a docker container, running on the same machine. 我在一个Docker容器中有PostgreSQL和Solr,它们在同一台机器上运行。 I am trying to do a dataimport from Postgres into Solr, but I am getting errors. 我试图将数据从Postgres导入Solr,但出现错误。 Here are the relevant parts of the log: 以下是日志的相关部分:

Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT * FROM formulas

org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Basically the connection is being refused/never made, but I'm confused. 基本上,连接被拒绝/从未建立,但我很困惑。

netstat -nltp

yields 产量

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      772/sshd
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1822/postgres
tcp6       0      0 :::22                   :::*                    LISTEN      772/sshd
tcp6       0      0 :::8983                 :::*                    LISTEN      28508/docker-proxy
tcp6       0      0 ::1:5432                :::*                    LISTEN      1822/postgres

And says that Postgres is listening on 127.0.0.1 . 并说Postgres正在监听127.0.0.1 Additionally, in my pg_hba.conf , I have 另外,在我的pg_hba.conf

local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 md5

which I believe are the correct settings for allowing connections. 我认为这是允许连接的正确设置。

My solrconfig.xml that is responsible for the data import settings looks like this: 我负责数据导入设置的solrconfig.xml如下所示:

<dataConfig>
  <dataSource driver="org.postgresql.Driver"
          url="jdbc:postgresql://127.0.0.1:5432/formulagrid"
          user="myuser"
          password="mypassword"/>
  <document>
    <entity name="formula" query="SELECT * FROM formulas">
      <field column="formula_id" name="id" />
      <field column="name" name="name" />
      <field column="formula" name="formula" />
    </entity>
  </document>
</dataConfig>

I have also tried the address jdbc:postgresql://localhost:5432/formulagrid . 我也尝试过地址jdbc:postgresql://localhost:5432/formulagrid

I don't know where else to go from here. 我不知道从这里还能去哪里。

Basically, you need to open a port on the container, something like: 基本上,您需要打开容器上的端口,例如:

docker run -it -p '<OUTSIDE_PORT>:<INSIDE_PORT>' <IMAGE_NAME>

Then on localhost you can connect to the Private IP or Public IP of the box to the - the is the port that solr is running on inside the container. 然后在localhost上,可以将框的“专用IP”或“公共IP”连接到-solr在容器内部运行的端口。

To connect from inside the container out, I would pass the IP and Port via an environment variable into the container, so something like: 为了从容器内部进行连接,我将通过环境变量将IP和端口传递到容器中,如下所示:

docker run -it -p '<OUTSIDE_PORT>:<INSIDE_PORT>' -e POSTGRESQL_ADDR=<IP>:<PORT> <IMAGE_NAME>

Then you can use ENV['POSTGRESQL_ADDR'] to connect outside the container. 然后,您可以使用ENV ['POSTGRESQL_ADDR']在容器外部进行连接。 Most likely, your private ip address will be used. 很可能会使用您的私人IP地址。

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

相关问题 连接到在Docker容器中运行的数据库时,sails-postgresql“ poolSize”太高错误 - sails-postgresql “poolSize” too high error when connecting to database running in Docker container 将Flask应用程序连接到在Docker容器中运行的Postgresql服务 - Connecting a flask application to a postgresql service running in a docker container 使用 GUI 连接到 docker 容器中的 Postgresql - Connecting to Postgresql in a docker container with a GUI Docker / Hibernate / PostgreSQL-将运行Hibernate / SpringBoot应用程序的容器与postgreSQL容器连接不起作用 - Docker/Hibernate/PostgreSQL - Connecting container running Hibernate/SpringBoot app with a postgreSQL container not working 将 PostgreSQL 数据库连接到 Spring 应用程序(均在 docker 中运行)连接被拒绝 - Connecting PostgreSQL database to Spring application (both running in docker) Connection refused 监视在Docker容器中运行的PostgreSQL的正确方法 - Proper way to monitor PostgreSQL running inside a docker container 在Docker中运行PostgreSql - Running PostgreSql inside Docker 从Docker容器内的PostgreSQL数据库生成转储文件 - Generating a dump file from PostgreSQL database inside a Docker container Docker容器连接到Postgres数据库 - Docker container connecting to Postgres database 从外部连接到 docker 容器中的 Postgresql - Connecting to Postgresql in a docker container from outside
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM