带有searchkick / elasticsearch的Docker Rails应用

DRi*_*ing 2 ruby-on-rails elasticsearch docker-compose

我将我的Rails应用程序从本地计算机移植到Docker容器中,并遇到了Elasticsearch / searchkick问题。我可以使其暂时工作,但我想知道是否有更好的方法。因此,elasticsearch的端口基本上不会与searchkick使用的默认localhost:9200匹配。现在,我在elasticsearch容器上使用了“ docker inspect”,并获得了实际IP,然后像searchkick文档所说的那样设置ENV ['ELASTICSEARCH_URL']变量,它可以工作。我有的问题是,如果我重新启动/更改IP有时会更改的容器,并且不得不再次经历整个过程,那将是一个痛苦。这是我的docker-compose.yml:

version: '2'
services:
  web:
    build: .
    command: rails server -p 3000 -b '0.0.0.0'
    volumes:
      - .:/living-recipe
    ports:
      - '3000:3000'
    env_file:
      - .env
    depends_on:
      - postgres
      - elasticsearch

  postgres:
    image: postgres

  elasticsearch:
    image: elasticsearch
Run Code Online (Sandbox Code Playgroud)

pho*_*oet 5

使用elasticsearch:9200。docker compose通过其名称公开容器。