Reputation: 1
I'm working on a Rails application using Searchkick with Elasticsearch running inside a Docker container.
When I try to start my Rails server, I get the following error:
bad URI (is not URI?): <"http://\"http:0">
However, when I run the search command inside the Rails console, it works fine:
DoctorRegister.search("Ali")
Code Setup
Searchkick.client =
Elasticsearch::Client.new(
url: ENV.fetch("ELASTICSEARCH_URL", "http://localhost:9200"),
retry_on_failure: 3,
transport_options: { request: { timeout: 20 } }
)
- ELASTICSEARCH_URL= http://host.docker.internal:9200
web:
build:
context: .
dockerfile: Dockerfile
container_name: rails_app
command: ["/bin/sh", "-c", "rails db:migrate && foreman start -f Procfile.dev"]
extra_hosts:
- "host.docker.internal:host-gateway"
external_links:
- "http://localhost:9200/"
volumes:
- .:/app:delegated
- /app/node_modules
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
environment:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}"
CLOUD_NAME: ${CLOUD_NAME}
API_KEY: ${API_KEY}
API_SECRET: ${API_SECRET}
URL: ${URL}
ELASTICSEARCH_URL: ${ELASTICSEARCH_URL}
ports:
- "3000:3000"
networks:
- app_network
env_file:
- .env
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.11
container_name: elasticsearch
ports:
- 9200:9200
healthcheck:
# test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -q '\"status\":\"green\"'"]
# test: curl -s http://localhost:9200/_cluster/health > /dev/null | exit 1
test:
[
"CMD-SHELL",
"curl -s http://localhost:9200/_cluster/health?pretty | grep status | grep -q '\\(green\\|yellow\\)'"
]
interval: 1m
timeout: 30s
retries: 5
environment:
- discovery.type=single-node
- xpack.security.enabled=false
Upvotes: 0
Views: 14