Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose can't connect to database from back-end server running in docker compose #13381

Open
Parthiba-Hazra opened this issue Jan 13, 2024 · 0 comments
Labels

Comments

@Parthiba-Hazra
Copy link

Cant connect to neo4j database from backend container running in same docker compose .. may be something wrong with my DATABASE_URL env. I also tried putting IP address to the url manually.

docker-compose.yaml -

version: '3'

services:
  backend:
    build:
      context: .
      dockerfile: ./Dockerfile.rust
    environment:
      - DATABASE_URL=bolt://neo4j:neo12345@neo4j:7687
    ports:
      - "8080:8080"
    depends_on:
      - neo4j

  frontend:
    build:
      context: .
      dockerfile: ./Dockerfile.react
    ports:
      - "8081:8081"
    depends_on:
      - backend

  neo4j:
    image: "neo4j:latest"
    ports:
      - "7474:7474"
      - "7687:7687"
    environment:
      NEO4J_AUTH: "neo4j/neo12345"

create client function -

async fn create_neo4j_client() -> Result<Graph, neo4rs::Error> {

    let x = "DATABASE_URL";
    let mut database_url = String::new();
    match env::var(x) {
        Ok(value) => {
            database_url = value;
            log::info!("The value of {} is: {}", x, database_url)
        } 
        Err(_) => {
            log::error!("{} is not set.", x)
        }
    }

    let config = ConfigBuilder::default()
        .uri(&database_url)
        .user(NEO4J_USER)
        .password(NEO4J_PASS)
        .db("neo4j")
        .fetch_size(500)
        .max_connections(10)
        .build()?;
    
    Graph::connect(config).await
}

OS - Ubuntu:23.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants