neo4j / docker-neo4j

Docker Images for the Neo4j Graph Database
Apache License 2.0
320 stars 168 forks source link

Client has not connected to the Neo4j server #413

Closed Shishkovskiy closed 1 year ago

Shishkovskiy commented 1 year ago

Hi there, I'm using .Net 6.0 Neo4jClient 5.1.3

I've been trying to run my app in Docker. During creating images I've got the error in output:

Connection with the server breaks due to ExtendedSocketException: Name or service not known Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0.

Please, take a look at these configuration files. If someone knows where the issue is, please lemme know because, to tell the truth, I have no idea what is wrong here. I appreciate any help you can provide.

appsettings.json

{
  "Neo4jConfiguration": {
    "Uri": "bolt://localhost:7687",
    "UserName": "neo4j",
    "Password": "6C2coi7kwnyYb7hNmfyvYNkyhxB!"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Information"
    }
  },
  "AllowedHosts": "*"
}

docker-compose.yml

version: '3.4'

services:
  server:
    image: "webapi-image"
    network_mode: "bridge"
    ports:
      - "8080:80"
    build:
      context: .
      dockerfile: Dockerfile
    stdin_open: true
    tty: true
    environment:
      - CHOKIDAR_USEPOLLING=true
      - NEO4JCONFIGURATION__URI=bolt://neo4j:7687
    depends_on:
      - neo4j
  neo4j:
    image: "neo4j:latest"
    network_mode: "bridge"
    ports:
      - "7687:7687"
      - "7474:7474"
    volumes:
      - ./neo4j/data:/data
      - ./neo4j/logs:/logs
      - ./neo4j/import:/var/lib/neo4j/import
      - ./neo4j/plugins:/plugins
    environment:
      - NEO4J_AUTH=neo4j/6C2coi7kwnyYb7hNmfyvYNkyhxB!
Shishkovskiy commented 1 year ago

I've already found the issues, to tell the truth there were several issues :) Now it works, maybe it'll be useful for someone who struggle with it as well.

  1. We didn't await when connect to the client and in this case we lost main exception
  2. Docker compose had wrong configuration
  3. When I run docker compose the app starts before the neo4j and of course we couldn't create a client because neo4j wasn't ready
version: '3.4'

services:
  server:
    image: "webapi-image"
    ports:
      - "8080:80"
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - NEO4JCONFIGURATION__URI=bolt://neo4j:7687
      - NEO4JCONFIGURATION__USERNAME=neo4j
      - NEO4JCONFIGURATION__PASSWORD=6C2coi7kwnyYb7hNmfyvYNkyhxB!
    depends_on:
      neo4j:
        condition: service_healthy
  neo4j:
    image: "neo4j:3.5"
    ports:
      - "7687:7687"
      - "7474:7474"
    volumes:
      - ./neo4j/data:/data
      - ./neo4j/logs:/logs
      - ./neo4j/import:/var/lib/neo4j/import
      - ./neo4j/plugins:/plugins
    environment:
      - NEO4J_AUTH=neo4j/6C2coi7kwnyYb7hNmfyvYNkyhxB!
    healthcheck:
      test: wget http://localhost:7474 || exit 1
      interval: 1s
      timeout: 10s
      retries: 10
      start_period: 3s
rweverwijk commented 1 year ago

Hi @Shishkovskiy good to see you got it working. Just in case you didn't notice, your neo4j password is in the code fragment. Change your neo4j password if this was the real password.

Cheers, Ron