【问题标题】:Can't launch sphinxsearch in docker无法在 docker 中启动 sphinxsearch
【发布时间】:2025-11-23 18:30:02
【问题描述】:

我正在尝试 dockerize 一个 Rails 应用程序。它使用 Sphinx 进行搜索,我无法让它通过 docker 运行。

这是当我运行 docker-compose up 并尝试执行搜索时发生的情况:

web_1     | [1fd79fbf-2e77-4af5-90ad-ae3637ada807]   Sphinx Query (1.9ms)  SELECT * FROM `field_core` WHERE MATCH('soccer') AND `sphinx_deleted` = 0 ORDER BY `name` ASC LIMIT 0, 10000
web_1     | [1fd79fbf-2e77-4af5-90ad-ae3637ada807] Completed 500 Internal Server Error in 27ms (ActiveRecord: 3.0ms)
web_1     | [1fd79fbf-2e77-4af5-90ad-ae3637ada807] 
web_1     | ThinkingSphinx::ConnectionError (Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (111)):
web_1     |   app/controllers/fields_controller.rb:7:in `search'

这是docker-compose run sphinx rake ts:index的结果:

sh: 1: searchd: not found

The Sphinx start command failed:
  Command: searchd --pidfile --config "/app/config/development.sphinx.conf"
  Status:  127
  Output:  See above

There may be more information about the failure in /app/log/development.searchd.log.

docker-compose.yml:

version: '3'
services:
  db:
    image: circleci/mysql:5.7
    restart: always
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3309:3309"
    expose:
      - '3309'
  web:
    build: .
    command: rails server -p 3000 -b '0.0.0.0'
    ports:
      - "3000:3000"
    expose:
      - '3000'
    depends_on:
      - db
      - sphinx
    volumes:
      - app:/app
  sphinx:
    container_name: sociaball_sphinx
    image: stefobark/sphinxdocker
    restart: always
    links:
      - db
    volumes:
    - /app/config/sphinxy.conf:/etc/sphinxsearch/sphinxy.conf
    - /app/sphinx:/var/lib/sphinx
volumes:
  mysql_data:
  app:

Dockerfile:

FROM ruby:2.4.1

RUN apt-get update && apt-get install -qq -y build-essential nodejs --fix-missing --no-install-recommends

RUN curl -s \
    http://sphinxsearch.com/files/sphinxsearch_2.3.2-beta-1~wheezy_amd64.deb \
    -o /tmp/sphinxsearch.deb \
&& dpkg -i /tmp/sphinxsearch.deb \
&& rm /tmp/sphinxsearch.deb \&& mkdir -p /var/log/sphinxsearch

WORKDIR /app

COPY Gemfile Gemfile.lock ./

RUN gem install bundler && bundle install --jobs 20 --retry 5

COPY . ./

EXPOSE 3000

CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

thinking_sphinx.yml:

development: &common
  min_infix_len: 1
  charset_table: "0..9, english, U+0021..U+002F"
  port: 9306
  address: sociaball_mysql_1
production:
  <<: *common

因此,rake 在 sphinx 容器中不可用,并且 sphinx 脚本在应用的容器中不可用。我做错了什么?

【问题讨论】:

  • 似乎 .deb 文件不再可用“未找到在此服务器上未找到请求的 URL /downloads/sphinxsearch_2.3.2-beta-1~wheezy_amd64.deb。" 如果无法下载,则无法安装。
  • 现在好像在sphinxsearch.com/files/…
  • 也许,但这不是问题。我已经尝试从多个来源安装 sphinx。

标签: ruby-on-rails docker docker-compose sphinx thinking-sphinx


【解决方案1】:

Thinking Sphinx 在运行 rake 任务时需要 Rails 应用的副本,因此您需要在 Sphinx 容器中拥有应用的副本。这将确保(一旦您捆绑了 gem)rake 存在于 Sphinx 容器中,其中也存在 Sphinx 二进制文件。

【讨论】:

    【解决方案2】:

    所以。

    我没有运行 rake 任务,而是直接在 sphinx 容器中完成了它的工作。像这样:

    docker-compose run --rm sphinx indexer \
    --config "/etc/sphinxsearch/sphinxy.conf" --all --rotate
    

    关于 500 错误。这是由thinking_sphinx.yml 中的错误配置引起的。它应该用 sphinx 而不是 db 指向远程主机:

    development: &common
      # ...
      address: sociaball_sphinx_1
    

    【讨论】:

      最近更新 更多