ruby-on-rails - 无法在 docker 中启动 sphinxsearch
问题描述
我正在尝试对 Rails 应用程序进行 dockerize 处理。它使用 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.
码头工人-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 脚本在应用程序的容器中不可用。我究竟做错了什么?
解决方案
Thinking Sphinx 在运行 rake 任务时需要 Rails 应用程序的副本,因此您需要在 Sphinx 容器中拥有应用程序的副本。这将确保(一旦您捆绑了 gem)rake 存在于 Sphinx 容器中,其中也存在 Sphinx 二进制文件。
推荐阅读
- java - 无法使后台服务“无法杀死”
- excel - 如何保持 vba 列表框中的文本值不转换为指数
- r - 在 R 中进行表操作时,求值嵌套太深错误
- reactjs - AG-GRID 不是 gridApi 上的 applyTransaction 方法
- java - 对使用 grails 分页感到困惑
- spatial - 多年数据的空间自相关
- android-studio - 如何解决 RangeError(index): Invalid value: Valid value range is empty: 1 in Flutter/Dart
- node.js - 多次写入时节点网络数据合并
- java - 如何转换 double x1 = input.nextDouble(); 成一个数组?
- vba - 如果该行出现在表格前面的页面上,则将表格前的行与表格一起移动