简体   繁体   中英

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. I am trying to do a dataimport from Postgres into Solr, but I am getting errors. 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 . Additionally, in my pg_hba.conf , I have

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:

<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 .

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.

To connect from inside the container out, I would pass the IP and Port via an environment variable into the container, so something like:

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. Most likely, your private ip address will be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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