简体   繁体   English

在 Docker + WSL 版本 2 中连接 ECONNREFUSED 127.0.0.1:27017 Mongo

[英]connect ECONNREFUSED 127.0.0.1:27017 Mongo in Docker + WSL version 2

The stack I'm using:我正在使用的堆栈:

  • WSL v2: WSL v2:
  NAME            STATE           VERSION
* Ubuntu-18.04    Running         2
  Ubuntu-20.04    Stopped         2
  • Docker in WSL: WSL 中的 Docker:
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:01:06 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
  • MongoDB 4.0.8 MongoDB 4.0.8

For MongoDB I'm using the official image:对于 MongoDB,我使用的是官方图片:

plonca@KAT-IT-1012:~$ docker run -d -p 27017-27019:27017-27019 --name mongodb_408 mongo:4.0.8

I can log into the container and check that the mongo is running and accessible:我可以登录容器并检查 mongo 是否正在运行并且可以访问:

plonca@KAT-IT-1012:~$ docker exec -it mongodb_408  bash
root@5b622e89bfef:/# mongo
MongoDB shell version v4.0.8
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0ae27473-4cc7-4d0d-9976-c922ea58b936") }
MongoDB server version: 4.0.8
Server has startup warnings:
2020-11-26T09:09:56.410+0000 I STORAGE  [initandlisten]
2020-11-26T09:09:56.410+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-11-26T09:09:56.410+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten]
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten]
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten]
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-11-26T09:09:57.140+0000 I CONTROL  [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

The Docker seems to be listening on port 27017: Docker 似乎正在监听端口 27017:

plonca@KAT-IT-1012:~$ sudo netstat -tulpn | grep :27017
tcp6       0      0 :::27017                :::*                    LISTEN      2114/docker-proxy

However while trying to connect from Mongo Compass (installed on Windows) to mongodb://127.0.0.1:27017 I get this error:但是,在尝试从 Mongo Compass(安装在 Windows 上)连接到mongodb://127.0.0.1:27017时,出现此错误:

connect ECONNREFUSED 127.0.0.1:27017

The connection string with container's IP address ( mongodb://172.17.0.2:27017 ) results in a time-out.带有容器 IP 地址 ( mongodb://172.17.0.2:27017 ) 的连接字符串导致超时。 How can I connect with my MongoDB running in a container from Mongo Compass installed on Windows?如何从安装在 Windows 上的 Mongo Compass 连接到在容器中运行的 MongoDB?

I was having the similar problem and check some answers and none of them worked for me.我遇到了类似的问题并检查了一些答案,但没有一个对我有用。

I have docker installed on my windows 10 machine.我的 windows 10 机器上安装了 docker。 I pulled the latest mongo image I ran the image with default options (no optional settings)我提取了最新的 mongo 图像我使用默认选项运行图像(没有可选设置) 没有可选设置 I got the same error: connect ECONNREFUSED 127.0.0.1:27017我得到了同样的错误:连接 ECONNREFUSED 127.0.0.1:27017

When I checked my containers I noticed that there is no ports assigned.当我检查我的容器时,我注意到没有分配端口。 没有端口

Then I tried to run the image with optional settings by adding a host port.然后我尝试通过添加主机端口来运行带有可选设置的图像。 (Also It's wise to add desired container name and path for volumes) (另外,为卷添加所需的容器名称和路径也是明智之举) 可选设置

With this optional settings I had no problem connecting with MongoDB Compass or any other MongoDB client.使用此可选设置,我可以毫无问题地连接 MongoDB Compass 或任何其他 MongoDB 客户端。

连接字符串 连接的

Hope this helps to anyone who is having the same issue.希望这对遇到同样问题的人有所帮助。

Okay, the answer to this is pretty simple, just follow the steps:好的,这个问题的答案很简单,只需按照以下步骤操作:

  1. Open task manager by pressing the key combination: Ctrl+Shift+Escape.按组合键打开任务管理器:Ctrl+Shift+Escape。
  2. Then Open services tab at the end of the bar that has the "Processes" "Performance" etc etc.然后在栏的末尾打开服务选项卡,其中包含“进程”、“性能”等。
  3. After opening the services tab, scroll down until you see "MongoDB".打开服务选项卡后,向下滚动直到看到“MongoDB”。
  4. Then right click on it, then click on start, after it started (after a minute), it should work now.然后右键单击它,然后单击开始,启动后(一分钟后),它现在应该可以工作了。

Hope this helps, lemme know if it does, or if it doesnt, cheers!希望这有帮助,让我知道它是否有用,或者如果没有,干杯!

暂无
暂无

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

相关问题 Windows上的本地Mongo-无法连接到服务器127.0.0.1:27017,连接尝试失败 - Local Mongo on Windows - couldn't connect to server 127.0.0.1:27017, connection attempt failed 在Windows 7上无法连接到服务器127.0.0.1:27017 - Couldn't connect to server 127.0.0.1:27017 on Windows 7 Mongodb:无法连接到 127.0.0.1:27017,原因:errno:10061 - Mongodb: Failed to connect to 127.0.0.1:27017, reason: errno:10061 无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? (Ubuntu 20.04,WSL2) - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (Ubuntu 20.04 ,WSL2) Docker和WSL错误:未经授权 - Docker and WSL error: UNAUTHORIZED .NET 项目无法从主机操作系统通过 localhost 连接到 WSL2 中的 Docker 容器 - .NET project not able to connect to Docker container in WSL2 via localhost from the host OS MongoDB 没有连接到服务器 127.0.0.1:27017 并显示目标机器主动拒绝它 - MongoDB isn't connecting to the server 127.0.0.1:27017 and showing target machine actively refused it 无法安装Yeoman错误:连接ECONNREFUSED - Trouble installing Yeoman Error: connect ECONNREFUSED 本地 mysql 仅在 windows 上连接 ECONNREFUSED - local mysql connect ECONNREFUSED only on windows WSL Ubuntu 20.04,在此 WSL 2 发行版中找不到命令“docker” - WSL Ubuntu 20.04, The command 'docker' could not be found in this WSL 2 distro
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM