使用PHP的Elasticsearch未相互链接

时间:2019-02-04 17:07:45

标签: docker

这是我的docker-compose:

version: "2"
services:
  mongodb:
    container_name: "elastic_backend_mongodb"
    restart: "always"
    image: "mongo:latest"
    volumes:
      - "./data/db/:/data/db"
    ports:
      - "27017:27017"
    command: --storageEngine wiredTiger
    networks:
      - "elastic_backend"
  php:
      build: ./develop
      container_name: "elastic_backend_php"
      restart: "always"
      environment:
        PHP_IDE_CONFIG: serverName=elastic_backend
      depends_on:
        - "mongodb"
        - "db"
        - "elasticsearch"
      expose:
        - "9000"
      volumes:
        - "../.:/var/www/html"
      networks:
        - "elastic_backend"
  nginx:
      image: "nginx:latest"
      container_name: "elastic_backend_nginx"
      restart: "always"
      volumes:
        - "./nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro"
        - "./nginx/conf.d:/etc/nginx/conf.d:ro"
      ports:
        - "80:80"
      volumes_from:
        - "php"
      networks:
        - "elastic_backend"
  db:
    container_name: "elastic_backend_mysql"
    restart: "always"
    image: "mysql:5.7"
    command: --max_allowed_packet=32505856
    environment:
      MYSQL_ROOT_PASSWORD: "asd"
      MYSQL_DATABASE: "elastic_backend"
    ports:
      - "3306:3306"
    volumes:
      - "./mysql:/var/lib/mysql"
    networks:
      - "elastic_backend"
  elasticsearch:
    container_name: "elastic_backend_es"
    image: elasticsearch:6.5.4
    environment:
      - discovery.type=single-node
    ports:
      - "9200:9200"
      - "9300:9300"
networks:
  elastic_backend:

因此,除php容器无法ping elasticsearch容器外,其他所有方法都工作正常。 db和mongodb容器可以从php容器ping通。我也尝试对docker使用“链接”和模拟指令,但没有任何运气。 那我在做什么错了?

我能够从主机(macos)获取elasticsearch的其余接口:

{
  "name": "cDsdqXL",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "010ETY4zT_C8XJu1IfON-g",
  "version": {
    "number": "6.5.4",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "d2ef93d",
    "build_date": "2018-12-17T21:17:40.758843Z",
    "build_snapshot": false,
    "lucene_version": "7.5.0",
    "minimum_wire_compatibility_version": "5.6.0",
    "minimum_index_compatibility_version": "5.0.0"
  },
  "tagline": "You Know, for Search"
}

1 个答案:

答案 0 :(得分:2)

PHP容器在这里无法访问elasticsearch容器,因为int size = bitmap.getRowBytes() * bitmap.getHeight(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); bitmap.copyPixelsToBuffer(byteBuffer); byteArray = byteBuffer.array(); // ... etc 服务未连接到elasticsearch网络。将此添加到elastic_backend服务下。

elasticsearch