#community-help

Laravel Package related Issue Resolved (`typesense/laravel-scout-typesense-driver`)

TLDR Jaeyson faced a network exception while setting up typesense/laravel-scout-typesense-driver on Docker. em1nos solved the issue by suggesting changing the hostname to "typesense".

Powered by Struct AI
heavy_plus_sign2
heart1
8
15mo
Solved
Join the chat
Jun 09, 2022 (15 months ago)
Jaeyson
Photo of md5-7be554727c46b2e8b385c6cb00b24d2c
Jaeyson
08:40 AM
hi! can i ask question that is laravel package-related? (typesense/laravel-scout-typesense-driver)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:52 AM
Yes, please post here and will get someone to respond.
heart1
Jaeyson
Photo of md5-7be554727c46b2e8b385c6cb00b24d2c
Jaeyson
08:55 AM
Kishore Nallan thanks! I’ll paste here since I asked this in github

Description

Hi! im getting networkexception, but im not sure if this has something to do with me setting up from docker or something else.

Http\Client\Exception\NetworkException with message 'Failed to connect to localhost port 8108: Connection refused for "".'

Steps to reproduce

1. added in my existing docker-compose.yml
...
  typsense:
    image: typesense/typesense:0.22.2
    container_name: typesense
    environment:
      TYPESENSE_DATA_DIR: /data
      TYPESENSE_API_KEY: xyz
    volumes:
      - /tmp/typesense-server-data:/data
    ports:
      - "8108:8108"
    restart: "no"
    networks:
      laravel:
...

2. docker compose up -d, then curl <http://localhost:8108/health> which returned {"ok":true}

3. Followed the readme instructions section:
- dependencies (guzzle7 adapter and laravel-scout-typesense-driver)
- service provider
- artisan vendor:publish ...
- config/scout.php
- Searchable trait as well as TypesenseDocument interface
- setting SCOUT_DRIVER value to typesense
- php artisan scout:import App\\Models\\Todo

Expected Behavior

returning the searched results

Actual Behavior

After the installation and syncing, I tried this inside tinker: Todo::search('Test')-&gt;get(); then i get this

>>> Images::search('female')->get()
Http\Client\Exception\NetworkException with message 'Failed to connect to localhost port 8108: Connection refused for "".'

Metadata

Typsense Version: 0.22.2

OS: macos 12.4

Laravel v8
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
12:39 PM
Shouldn't it connect to host "typesense" instead of localhost? It's not the app container (localhost) that's running typesense, right?

I'm guessing a bit now. I'm using Lando, which is using docker under the hood, so it's a bit different than using docker directly.
heavy_plus_sign2
12:42
em1nos
12:42 PM
Also, this is assuming you're running the web/php server in a separate container as well, and not natively on your machine.
Jaeyson
Photo of md5-7be554727c46b2e8b385c6cb00b24d2c
Jaeyson
12:56 PM
em1nos ah mybad, took me days before i realized the hostname is typesense (container_name) 🤦. It’s now working, thanks so much for pointing it out!!!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:44 PM
Thanks for the help em1nos
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
01:46 PM
I'm glad I could help :)