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

局域网内Docker容器中Node.js服务器无响应,请求排查

Troubleshooting: Can't Access Dockerized Node.js Server on Linux from Mac Client

Hey David, let's work through this step by step to narrow down whether it's a Docker configuration issue or a network problem in your LAN. Here's how to debug:

First, Confirm the Baseline

You mentioned running the Node.js server directly on the Linux machine (without Docker) — did that work when accessing from your Mac?

  • If yes: The core LAN connectivity is fine, so we can focus on Docker-specific issues.
  • If no: We need to fix the LAN network first before looking at Docker.

Docker Configuration Checks (If Direct Node Server Works)

1. Verify Docker Port Mapping

Run docker ps on your Linux machine and look at the PORTS column for your Node container. It should look like:

0.0.0.0:3000->3000/tcp

or

:::3000->3000/tcp
  • If it shows 127.0.0.1:3000->3000/tcp, the port is only bound to Linux's loopback interface. To fix this, restart your container with the port mapping explicitly set to listen on all interfaces:
    docker run -d -p 0.0.0.0:3000:3000 <your-image-name>
    

2. Check if Node.js is Listening on the Correct Address Inside the Container

Even if Docker maps the port, your Node app might be only listening on 127.0.0.1 (loopback inside the container). To check:

  1. Enter the container:
    docker exec -it <container-id-or-name> bash
    
  2. Run this command to check listening ports (install net-tools first if needed with apt install net-tools):
    netstat -tulpn | grep 3000
    
    You should see something like 0.0.0.0:3000 (not 127.0.0.1:3000).
  • If it's only listening on loopback, update your Node code to listen on all interfaces:
    app.listen(3000, '0.0.0.0', () => {
      console.log('Server running on port 3000');
    });
    

3. Test Local Access to the Container on Linux

From the Linux machine itself, run:

curl http://localhost:3000

or

curl http://<linux-lan-ip>:3000
  • If this works, Docker is configured correctly — the issue is in your LAN network.
  • If this fails, fix the Docker/Node configuration first.

LAN Network Checks (If Docker Local Access Works)

1. Use the Linux LAN IP Directly Instead of .local

First, get your Linux machine's LAN IP by running:

ip addr

Look for the inet address under your active network interface (e.g., eth0 for wired, wlan0 for wireless — usually something like 192.168.1.100).

On your Mac, try accessing http://<linux-lan-ip>:3000 directly. This avoids any mDNS (.local) resolution issues.

2. Check Linux Firewall Settings

Linux firewalls (like ufw or firewalld) might block incoming traffic on port 3000:

  • For ufw:
    1. Check current rules:
      sudo ufw status
      
    2. If port 3000 isn't allowed, add it:
      sudo ufw allow 3000/tcp
      
  • For firewalld:
    1. Check open ports:
      sudo firewall-cmd --list-ports
      
    2. Add the port permanently:
      sudo firewall-cmd --add-port=3000/tcp --permanent
      sudo firewall-cmd --reload
      

3. Confirm Mac and Linux Are on the Same LAN Segment

On your Mac, run this to get your LAN IP:

# For wireless
ipconfig getifaddr en0
# For wired
ipconfig getifaddr en1

Make sure this IP is in the same subnet as your Linux machine (e.g., both start with 192.168.1.x). If not, check your router/VLAN settings.

4. Debug mDNS Resolution (If Using .local)

If you prefer using <computer-name>.local, test if mDNS is resolving correctly on your Mac:

ping <linux-computer-name>.local
  • If the ping fails or resolves to the wrong IP, your mDNS setup might be broken. Try restarting the Linux machine's avahi-daemon (if installed) or use the direct LAN IP instead.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:32:35