Ruby on rails Solr位于带有太阳黑子轨道的单独docker容器上

Ruby on rails Solr位于带有太阳黑子轨道的单独docker容器上,ruby-on-rails,docker,solr,docker-compose,sunspot-rails,Ruby On Rails,Docker,Solr,Docker Compose,Sunspot Rails,我正在尝试将正在工作的Rails应用程序移动到docker环境 遵循UNIX(/docker)理念,我希望每个服务都有自己的容器 我设法让redis和postgres工作得很好,但我很难让slor和rails互相交谈 行执行时,在文件app/models/spree/sunspot/search\u decorator.rb中 @solr_search.execute 控制台上出现以下错误: Errno::EADDRNOTAVAIL (Cannot assign requested addre

我正在尝试将正在工作的Rails应用程序移动到docker环境

遵循UNIX(/docker)理念,我希望每个服务都有自己的容器

我设法让redis和postgres工作得很好,但我很难让slor和rails互相交谈

行执行时,在文件
app/models/spree/sunspot/search\u decorator.rb中

@solr_search.execute
控制台上出现以下错误:

Errno::EADDRNOTAVAIL (Cannot assign requested address - connect(2) for "localhost" port 8983):
在研究解决方案时,我发现人们只是将solr安装在与rails应用程序相同的容器中。但我宁愿把它放在一个单独的容器里

这是我的
config/sunspot.yml

development:
  solr:
    hostname: localhost
    port: 8983
    log_level: INFO
    path: /solr/development
docker compose.yml
文件

version: '2'
services:
  db:
    (...)

  redis:
    (...)

  solr:
    image: solr:7.0.1

    ports:
      - "8983:8983"

    volumes:
      - solr-data:/opt/solr/server/solr/mycores

    entrypoint:
      - docker-entrypoint.sh
      - solr-precreate
      - mycore

    networks:
      - backend

  app:
    build: .

    env_file: .env

    environment:
      RAILS_ENV: $RAILS_ENV

    depends_on:
      - db
      - redis
      - solr

    ports:
      - "3000:3000"

    tty: true

    networks:
      - backend

volumes:
  solr-data:
  redis-data:
  postgres-data:

networks:
  backend:
    driver: bridge

有什么建议吗?

在docker compose文件中声明服务时,容器的名称将作为主机名。因此,您的
solr
服务将作为
solr
backend
网络中提供

我从您的错误中看到,ruby代码正在尝试连接到
localhost:8983
,而它应该连接到
solr:8983


可能您还需要在
config/sunspot.yml
中更改主机名,但我不使用solr,所以我不确定这一点。

当您在docker compose文件中声明服务时,容器的名称将作为主机名。因此,您的
solr
服务将作为
solr
backend
网络中提供

我从您的错误中看到,ruby代码正在尝试连接到
localhost:8983
,而它应该连接到
solr:8983


可能您还需要在
config/sunspot.yml
中更改主机名,但我不与solr合作,因此我不确定这一点。

您的config/sunspot.yml应该具有以下内容:

development:
  solr:
    hostname: solr # since our solr instance is linked as solr
    port: 8983
    log_level: WARNING
    solr_home: solr
    path: /solr/mycore 
    # this path comes from the last command of our entrypoint as
    # specified in the last parameter for our solr container
如果你看到

Solr::Error::Http (RSolr::Error::Http - 404 Not Found
Error:     Not Found

URI: http://localhost:8982/solr/development/select?wt=json
在以下位置使用管理界面创建新核心:

http://localhost:8982/solr/#/~cores

或使用以下命令:

docker-compose exec solr solr create_core -c development
我写了一篇关于这个的博客:


希望这能帮助那些稍后来到这里的人。

您的配置/sunspot.yml应该具备以下功能:

development:
  solr:
    hostname: solr # since our solr instance is linked as solr
    port: 8983
    log_level: WARNING
    solr_home: solr
    path: /solr/mycore 
    # this path comes from the last command of our entrypoint as
    # specified in the last parameter for our solr container
如果你看到

Solr::Error::Http (RSolr::Error::Http - 404 Not Found
Error:     Not Found

URI: http://localhost:8982/solr/development/select?wt=json
在以下位置使用管理界面创建新核心:

http://localhost:8982/solr/#/~cores

或使用以下命令:

docker-compose exec solr solr create_core -c development
我写了一篇关于这个的博客:


希望这能帮助那些稍后来到这里的人。

请在问题中包含您的yml文件:外部链接可能会消失anytime@lifeisfoo完成,谢谢你指出。请在问题中包括你的yml文件:外部链接可能会消失anytime@lifeisfoo完成,谢谢您指出。当主机名为
solr
时,我得到另一个错误:
RSolr::error::Http-404未找到错误:未找到URI:http://solr:8983/solr/development/select?wt=json
我将查看是否找到解决此问题的方法。看起来我走的是正确的道路:)是的,现在你到达了主机,你的问题错误被解决了。我认为,如果您需要404问题(solr配置错误)的帮助,您应该创建另一个问题。因为这不再是docker的问题。当主机名为
solr
时,我得到另一个错误:
RSolr::error::Http-404未找到错误:未找到URI:http://solr:8983/solr/development/select?wt=json
我将查看是否找到解决此问题的方法。看起来我走的是正确的道路:)是的,现在你到达了主机,你的问题错误被解决了。我认为,如果您需要404问题(solr配置错误)的帮助,您应该创建另一个问题。因为这不再是码头工人的问题了。