这是我的docker-compose.yml
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
image: php:7.0-fpm
expose:
- 9000
volumes_from:
- app
links:
- elastic
app:
image: php:7.0-fpm
volumes:
- .:/var/www/html
command: "true"
elastic:
image: elasticsearch:2.3
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/logs:/usr/share/elasticsearch/logs
expose:
- "9200"
ports:
- "9200:9200"
当我尝试通过访问localhost:9200来访问Elasticsearch时,它可以工作.
但是当我尝试使用PHP创建索引时,我收到以下错误:
Fatal error: Uncaught
Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive
nodes found in your cluster in
这是客户端代码:
用于实例化Elasticsearch对象的代码:
如果我是var_dump($es),它会转储Elasticsearch客户端对象.
但是当我尝试创建索引时,它会抛出错误.
更新
这一页.我试过了
$es = Client::getClient();
try {
// Create User Index
$userIndex = new UserIndex($es);
var_dump($userIndex->createIndex('users'));
} catch (Exception $e) {
var_dump($es->transport->getLastConnection()->getLastRequestInfo());
}
现在它显示了我的卷曲错误,即
[“curl”] array(2) { [“error”] “Failed to connect to localhost port
9200: Connection refused” [“errno”] 7
最佳答案
您尝试连接到localhost,但您需要连接到“弹性”主机.
尝试从php连接到elasticsearch,如下所示:
尝试从php连接到elasticsearch,如下所示:
$hosts = [
'elastic',// elastic host was added to you hosts file automatically
];
$client = ClientBuilder::create()
->setHosts($hosts)
->build();
Containers for the linked service will be reachable at a hostname identical to the alias,or the service name if no alias was specified.