Reputation: 67
I am running a neo4j graph database inside a docker container. I've written another service in Go that should be able to execute queries from its respective container. I cannot however get the connection between those two containers established.
the dockerfile
of my database:
version: "3"
services:
neo4j-db:
image: neo4j:latest
ports:
- "7474:7474"
- "7473:7473"
- "7687:7687"
expose:
- 7474
networks:
app_net:
ipv4_address: 172.18.18.10
volumes:
- //C/Users/<user>/Desktop/neoj4/4.0/config:/conf
networks:
app_net:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.18.18.0/24
My neo4j.conf
:
dbms.connector.https.advertised_address=localhost:7473
dbms.default_listen_address=0.0.0.0
dbms.connector.http.advertised_address=localhost:7474
dbms.memory.pagecache.size=512M
dbms.connector.bolt.advertised_address=127.18.18.10:7687
dbms.tx_log.rotation.retention_policy=100M size
dbms.directories.logs=/logs
And finally inside my Go container:
uri := "bolt://127.18.18.10:7687"
username := "neo4j"
password := "test"
var (
err error
driver neo4j.Driver
session neo4j.Session
result neo4j.Result
greeting interface{}
)
fmt.Println("Connecting to Neo4j")
driver, err = neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), useConsoleLogger(neo4j.ERROR))
if err != nil {
fmt.Println("ERROR:" , err)
}
defer driver.Close()
fmt.Println("Getting Session")
session, err = driver.Session(neo4j.AccessModeWrite)
if err != nil {
fmt.Println("ERROR:" , err)
}
defer session.Close()
When calling the function the execution gets stuck after fmt.Println("Getting Session")
without throwing any errors for 30 seconds and then simply terminates.
I also made sure to have both containers on the same network (app_net
). I can ping between the containers without issue. However, trying telnet from the go-container to neo4j yields Unable to connect to remote host: Connection refused
.
I'm not sure what I'm doing wrong. Browser access on neo4j works and from what I see the containers are on the same network.
Any advice or ideas are greatly appreciated.
Upvotes: 1
Views: 902
Reputation: 67
After spending some additional time, I've managed to get it working. I took the following steps:
uri
(i.e. "bolt://container_name"
). if driver, err = neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), func(config *neo4j.Config) {
config.Log = neo4j.ConsoleLogger(neo4j.ERROR)
config.Encrypted = false
}); err != nil {
return err
}
defer driver.Close()
Upvotes: 3