You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10环境下Docker容器MongoDB无法通过Compass连接怎么办?

Fixing MongoDB Compass Connection Issues to Docker Container on Windows 10

Let’s work through this problem step by step—there are a few common culprits here, and we’ll rule them out one by one:

1. Verify Port Mapping is Working Correctly

First, let’s confirm Docker is actually forwarding traffic from your Windows host’s port 28000 to the container’s 27017 port.

  • Run docker ps in your command prompt. Look for the PORTS column for your mongodb container. It should show something like 0.0.0.0:28000->27017/tcp or :::28000->27017/tcp. If it shows 127.0.0.1:28000->27017/tcp, that means the port is only bound to your Docker host’s loopback interface, not accessible from your Windows machine’s network.
  • On your Windows machine, run netstat -ano | findstr :28000 to check if the port is being listened on. You should see a line with LISTENING and a PID—this PID should match the Docker process (confirm with Task Manager).

2. Ensure MongoDB is Bound to All IP Addresses

By default, MongoDB 3.4 binds only to 127.0.0.1 (loopback) inside the container, which means it won’t accept connections from outside the container—even if the port is mapped.

To fix this, start the MongoDB container with the --bind_ip_all flag to allow connections from any IP:

# First stop and remove the existing container (if you don't have data to preserve)
docker stop mongodb
docker rm mongodb

# Start a new container with the bind IP flag
docker container run -p 28000:27017 --name mongodb --detach mongo:3.4 --bind_ip_all

If you have data to keep, you can either:

  • Use a Docker volume to persist data (recommended for future use), or
  • Exec into the container, modify the mongod.conf file to set bindIp: 0.0.0.0, then restart the MongoDB service inside the container.

3. Check Windows Firewall Settings

Windows Firewall might be blocking incoming traffic on port 28000. Here’s how to fix it:

  • Open Windows Defender Firewall > Advanced Settings > Inbound Rules.
  • Click New Rule... and select Port as the rule type.
  • Choose TCP, enter 28000 as the specific local port, then click Next.
  • Select Allow the connection, choose when the rule applies (Domain, Private, Public—adjust based on your network), name the rule, and save it.

You can also temporarily disable the firewall to test if it’s the issue (remember to re-enable it afterward!).

4. Validate Your Compass Connection String

Make sure you’re using the correct connection string in MongoDB Compass:

  • Use mongodb://<your_windows_ip>:28000 (replace <your_windows_ip> with your actual 192.168.x.x address).
  • Since you didn’t set up authentication when starting the container, leave the username/password fields blank.
  • Avoid using localhost in the connection string—use your actual Windows IP instead, as localhost in Compass refers to your Windows machine, but we need to target the port Docker is forwarding.

5. Test Connectivity with a Simple Tool

If Compass still isn’t working, test the connection with PowerShell’s Test-NetConnection to rule out Compass-specific issues:

Test-NetConnection <your_windows_ip> -Port 28000

If you see TcpTestSucceeded : True, the port is reachable—so the issue is likely with Compass settings. If not, go back to steps 1-3.

内容的提问来源于stack exchange,提问作者Steephen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:03:54