neo4j-php / neo4j-php-client

Php client and driver for neo4j database
https://neo4j.com/developer/php/
MIT License
160 stars 40 forks source link

Error: "Cannot connect to any server on alias" when connecting to a neo4j docker container #212

Closed CalElAn closed 2 months ago

CalElAn commented 2 months ago

Describe the bug I am unable to connect to a neo4j docker container. I am connecting from a laravel sail container.

My docker-compose file:

    neo4j:
        container_name: neo4j
        image: neo4j:5.21
        ports:
            - 7474:7474
            - 7687:7687
        environment:
            - NEO4J_AUTH=neo4j/${NEO4J_PASSWORD}
            - NEO4J_apoc_export_file_enabled=true
            - NEO4J_apoc_import_file_enabled=true
            - NEO4J_apoc_import_file_use__neo4j__config=true
            - NEO4J_PLUGINS=["apoc", "graph-data-science"]
        volumes:
            - sail-neo4j-data:/data
            - sail-neo4j-logs:/logs
            - sail-neo4j-import:/var/lib/neo4j/import
            - sail-neo4j-plugins:/plugins
        networks:
            - sail

networks:
    sail:
        driver: bridge
volumes:
    sail-neo4j-data:
        driver: local
    sail-neo4j-logs:
        driver: local
    sail-neo4j-import:
        driver: local
    sail-neo4j-plugins:
        driver: local

The laravel container is on the same network (sail) as the neo4j container. I am also able to connect from my browser (http://localhost:7474/), and I am able to connect to the server using the neo4j username and the password I specified in the .env file.

To Reproduce Steps to reproduce the behavior:

  1. Start a laravel app following the instructions here:https://laravel.com/docs/11.x/installation#docker-installation-using-sail
  2. Remember to add the above to the docker-composer.yml and specify the NEO4J_PASSWORD in your .env file
  3. Run a query using the following client setup:
    
    use Laudis\Neo4j\ClientBuilder;
    use Laudis\Neo4j\Contracts\ClientInterface;

ClientBuilder::create() ->withDriver( 'bolt', 'bolt://neo4j:@localhost:7687', ) ->build();


7. See error:
Cannot connect to any server on alias: bolt with Uris: ('bolt://neo4j:<NEO4J_PASSWORD>@localhost:7687')

**Expected behavior**
The client should be able to connect

**Desktop (please complete the following information):**
 - Library version:  * dev-main
 - Neo4j Version: 5.21
 - PHP version: 8.39
 - OS: windows 11

**Additional context**
I am able to connect to an auradb instance normally, so I am not sure what the problem here is
exaby73 commented 2 months ago

Hey @CalElAn. I see from your library version, you're using dev-main. Could you confirm if this is still reproducible on the latest stable version of the library?

CalElAn commented 2 months ago

Hi, thanks for your reply. Yes, the bug is still reproducible on version 3.0.6. I just checked

I was using dev-main because neo4j-php-client requires psr/http-message ^1.0, but the package is fixed to 2.0 (lock file version) by a partial update and that version does not match.

In order to check if the bug is reproducible, I added the -W flag to the composer require command, and the bug still exists

CalElAn commented 2 months ago

I was able to find a solution. I needed to use the container's address in the code, not localhost.

I just had to change localhost to neo4j.