我正试图将LaravelScout
与docker一起使用,我遵循了docs Laravel Scout docs我完成了安装所需的所有步骤,一切都按预期运行。但是每当我尝试搜索数据时,我都会收到这个错误CCD_。我正在从insomnia
向laravel
路由web发送请求。
-
注意:-当我访问时http://127.0.0.1:7720/将显示meilisearch默认页面。也尝试了
curl -kvs --http2 --request GET 'http://localhost:7720/indexes'
,它工作正常并返回Connected to localhost (127.0.0.1) port 7720 (#0)
,但每当我从insomnia
发送时,我都会收到错误
再现错误的步骤
-
尝试用keword
PENDING
搜索Event
模型。AppModelsEvent::search('PENDING')->get()
-
事件模型类
<?php
namespace AppModels;
use IlluminateSupportStr;
use LaravelScoutSearchable;
use DatabaseFactoriesEventFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentFactoriesHasFactory;
class Event extends Model
{
use HasFactory;
use Searchable;
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = ['event_type_id', 'status'];
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->id = Str::uuid()->toString();
});
}
public static function newFactory(): EventFactory
{
return EventFactory::new();
}
}
- Laravel
.env
文件
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://127.0.0.1:7720
MEILISEARCH_KEY=masterKey
MEILISEARCH_NO_ANALYTICS=false
MEILISEARCH_NO_SENTRY=true
- docker-compose.yml
version: "3.7"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: app:latest
container_name: app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
ports:
- 9000:9000
networks:
- app-network
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- app-network
ports:
- 3307:3306
nginx:
image: nginx:alpine
container_name: nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- app-network
phpmyadmin:
image: phpmyadmin
container_name: pma
restart: unless-stopped
ports:
- 8283:80
environment:
PMA_HOSTS: ${DB_HOST}
PMA_ARBITRARY: 1
PMA_USER: ${DB_USERNAME}
PMA_PASSWORD: ${DB_PASSWORD}
networks:
- app-network
meilisearch:
image: getmeili/meilisearch:latest
container_name: meilisearch
restart: unless-stopped
ports:
- 7720:7700
environment:
MEILI_NO_ANALYTICS: ${MEILISEARCH_NO_ANALYTICS}
MEILI_NO_SENTRY: ${MEILISEARCH_NO_SENTRY}
MEILI_MASTER_KEY: ${MEILISEARCH_KEY}
networks:
- app-network
volumes:
- ./meilisearch-data:/meilisearch-data
networks:
app-network:
driver: bridge
我发现问题是我使用meilisearch
作为docker服务,所以我应该指定MEILISEARCH_HOST
env变量来指向服务名称,如DB_HOST=db
(docker服务名称(。所以在这种情况下,我将MEILISEARCH_HOST
从MEILISEARCH_HOST=http://127.0.0.1:7720
更改为MEILISEARCH_HOST=meilisearch:7700
,现在一切都如预期的那样正常工作。
由于您的美丽搜索服务被称为"meilisearch";,你能试试MEILISEARCH_HOST=http://meilisearch:7720
吗?
我注意到您正在向web.php
中的路由发出外部API请求,这可能是您的问题的原因。在cURL error 7: Failed to connect to 127.0.0.1 port 7720: Connection refused
0中设置路线,然后重试
Brother,首先,容器不公开环境变量。如果可以指定类似env_file
的内容或使用secrets
方法,则可以访问容器中的环境变量。而且,像SCOUT_DRIVER=meilisearch MEILISEARCH_HOST=http://127.0.0.1:7720
这样的环境变量没有分配给任何服务。也许这阻止了它的启动。