Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Rails app with searchkick/elasticsearch

Im porting my rails app from my local machine into a docker container and running into an issue with elasticsearch/searchkick. I can get it working temporarily but Im wondering if there is a better way. So basically the port for elasticsearch isnt matching up with the default localhost:9200 that searchkick uses. Now I have used "docker inspect" on the elasticsearch container and got the actual IP and then set the ENV['ELASTICSEARCH_URL'] variable like the searchkick docs say and it works. The problem Im having is that is a pain if I restart/change the containers the IP changes sometimes and I have to go through the whole process again. Here is my 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
like image 690
DRing Avatar asked Aug 13 '16 13:08

DRing


1 Answers

use elasticsearch:9200 instead of localhost:9200. docker compose exposes the container via it's name.

like image 98
phoet Avatar answered Oct 09 '22 06:10

phoet