简体   繁体   English

如何在 Docker 中连接容器外的 mg_client?

[英]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.我正在尝试访问 docker 容器内的 mg_client,但不幸的是,我无法连接它。 I have followed instructions from the docs here我已按照此处文档的说明进行操作

docker-compose.yaml 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 - CLI 返回错误 -

在此处输入图像描述

Memgraph is successfully initialized as shown.如图所示,Memgraph 已成功初始化。

在此处输入图像描述

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. PS:我正在尝试使用同时运行的 Memgraph、Neo4j 和 RedisGraph 创建一个项目,并使用 Python 库/适配器访问每个数据存储。 This is the very initial step towards it.这是朝着它迈出的第一步。

Feedback would be appreciated.反馈将不胜感激。

If standard docker run is used, I've managed to connect.如果使用标准docker run ,我已经成功连接。 Memgraph run command is Memgraph 运行命令是

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

Memgraph Docker 运行 mg_client

If docker-compose is used, a network has to be defined:如果使用docker-compose ,则必须定义网络:

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.请注意确切的网络名称,因为docker-compose{{folder_name}}_{{network_name}}作为网络名称。 In my case, that's stack_issue_test_network .就我而言,那是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.由于docker-compose 3.5,可以定义网络名称,但我在Ubuntu 20.04上使用的是1.25。

The benefit of using this is that the IP resolution doesn't have to be done.使用它的好处是不必进行 IP 分辨率。 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.如果升级到 Memgraph 1.3,可以使用--log-level=TRACE --also-log-to-stderr查看更多日志。
  • 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. mg_client是一个不推荐使用的工具,因为您使用的是 Ubuntu,因此直接从主机安装mgconsole和查询 Memgraph 实例应该相对简单。 There is a plan to package mgconsole instead of mg_client in the future.未来有计划用 package mgconsole代替mg_client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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