简体   繁体   中英

How to connect mg_client outside container in Docker?

I am trying to access mg_client inside a docker container but unfortunately, I am unable to connect it. I have followed instructions from the docs here

docker-compose.yaml

version: "3"
services:
  redis:
    image: redislabs/redisgraph
    container_name: redis
    restart: unless-stopped
    ports:
      - "6379:6379"

  memgraph:
    image: memgraph
    container_name: memgraph
    restart: unless-stopped
    ports:
      - "7687:7687"

CLI returns back an error -

在此处输入图像描述

Memgraph is successfully initialized as shown.

在此处输入图像描述

Strangely, if I execute it inside the container, I am able to connect.

在此处输入图像描述

What can be a possible mistake from my end?

PS: I am trying to create a Project with Memgraph, Neo4j, and RedisGraph running simultaneously and accessing each datastore using Python libs/adapter. This is the very initial step towards it.

Feedback would be appreciated.

If standard docker run is used, I've managed to connect. Memgraph run command is

docker run --rm -p 7687:7687 --name test memgraph

Memgraph Docker 运行 mg_client

If docker-compose is used, a network has to be defined:

version: "3"
services:
  memgraph:
    image: memgraph:1.3.0-community
    container_name: memgraph
    networks:
      - test_network
    container_name: memgraph
    restart: unless-stopped
    ports:
      - "7687:7687"
networks:
  test_network:
    driver: bridge

Memgraph docker-compose up

Please take care about the exact network name because docker-compose takes the {{folder_name}}_{{network_name}} as a network name. In my case, that's stack_issue_test_network . Since docker-compose 3.5, the network name can be defined, but I'm using 1.25 on Ubuntu 20.04 at this time.

The benefit of using this is that the IP resolution doesn't have to be done. The container name can be used instead.

连接到由 docker compose 运行的 Memgraph 实例

A couple of final notes:

  • If you upgrade to Memgraph 1.3, --log-level=TRACE --also-log-to-stderr could be used to see more logs.
  • mg_client is a deprecated tool, since you are using Ubuntu, it should be relatively straightforward to install mgconsole and query Memgraph instances directly from the host machine. There is a plan to package mgconsole instead of mg_client in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM