Windows 在Docker+中连接EConrefuse127.0.0.1:27017 Mongo;WSL版本2

Windows 在Docker+中连接EConrefuse127.0.0.1:27017 Mongo;WSL版本2,windows,mongodb,docker,wsl-2,Windows,Mongodb,Docker,Wsl 2,我正在使用的堆栈: WSL v2: WSL中的Docker: MongoDB 4.0.8 对于MongoDB,我使用的是官方图像: plonca@KAT-IT-1012:~$ docker run -d -p 27017-27019:27017-27019 --name mongodb_408 mongo:4.0.8 我可以登录到容器并检查mongo是否正在运行和可访问: plonca@KAT-IT-1012:~$ docker exec -it mongodb_408 bash

我正在使用的堆栈:

  • WSL v2:
  • WSL中的Docker:
  • MongoDB 4.0.8
对于MongoDB,我使用的是官方图像:

plonca@KAT-IT-1012:~$ docker run -d -p 27017-27019:27017-27019 --name mongodb_408 mongo:4.0.8
我可以登录到容器并检查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()
---

>

码头工人似乎正在监听27017端口:

plonca@KAT-IT-1012:~$ sudo netstat -tulpn | grep :27017
tcp6       0      0 :::27017                :::*                    LISTEN      2114/docker-proxy
但是,在尝试从Mongo Compass(安装在Windows上)连接到
mongodb://127.0.0.1:27017
我收到了这个错误:

connect ECONNREFUSED 127.0.0.1:27017
具有容器IP地址的连接字符串(
mongodb://172.17.0.2:27017
)会导致超时。如何连接在Windows上安装的Mongo Compass容器中运行的MongoDB

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