paion-data / aristotle

A web servide enables you to create knowledge graph.
https://aristotle-ws.com
3 stars 0 forks source link

Fix Docker Compose startup error - "Unable to connect to db:7687 #24

Closed Doom9527 closed 4 days ago

Doom9527 commented 5 days ago

The web container did not start after the db container started successfully. I've changed docker-compose to this:

services:
  web:
    build: .
    ports:
      - "8080:8080"
    environment:
      NEO4J_URI: bolt://db:7687
      NEO4J_USERNAME: neo4j
      NEO4J_PASSWORD: 12345678
      NEO4J_DATABASE: neo4j
    depends_on:
      db:
        condition: service_healthy
  db:
    image: neo4j:latest
    environment:
      NEO4J_AUTH: neo4j/12345678
      NEO4JLABS_PLUGINS: "[\"apoc\"]"
    volumes:
      - neo4j-data:/data
    ports:
      - "7474:7474"
      - "7687:7687"
    healthcheck:
      test: ["CMD-SHELL", "curl", "--fail", "http://db:7474/db/data"]
      interval: 30s
      timeout: 10s
      retries: 5

volumes:
  neo4j-data:

It still doesn't work. By entering docker inspect --format='{{json.State. Health}}' db, I find that curl is not installed inside the neo4j container, causing the health check to fail. I solved this problem by switching to wget.

Changelog

Added

    healthcheck:
      test: wget --quiet --spider http://db:7474/db/data && echo 'Health check passed' || echo 'Health check failed'
      interval: 10s
      timeout: 3s
      retries: 5