我无法通过 public IP 访问我的 Docker Node.js 容器

I can not access by public IP to my Docker Node.js container

我有一个 Docker Node.js 容器监听端口 4757 与 NET 库,使用我的 Public IP。

server listening on {"address":"144.xxx.xxx.66","family":"IPv4","port":4757}

当我从我的电脑访问时我没有问题,但是如果我尝试访问我的手机或其他设备连接被拒绝 (ERR_ADDRESS_UNREACHABLE)。

应用程序在 docker-composer 在其他笔记本电脑上正常工作,问题出在我的新笔记本电脑上。这是我的local.yml

version: '3'

volumes:
  local_postgres_data: {}
  local_postgres_data_backups: {}

services:
  django: &django
  build:
    context: .
    dockerfile: ./compose/local/django/Dockerfile
  image: hegeo_local_django
  depends_on:
    - postgres
  volumes:
    .:/app
  env_file:
    - ./.envs/.local/.django
    - ./.envs/.local/.postgres
  ports:
    - "8000:8000"
  command: /start
  networks:
    default:
      ipv4_address: 144.xxx.xxx.3

  node:
    build:
      context: .
      dockerfile: ./compose/production/nodejs/Dockerfile
    image: hegeo_node
    depends_on:
      - postgres
    links:
      - postgres
    ports:
      - "4757:4757"
    networks:
      default:
        ipv4_address: 144.xxx.xxx.66

  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    image: hegeo_production_postgres
    volumes:
      - local_postgres_data:/var/lib/postgresql/data
      - local_postgres_data_backups:/backups
    env_file:
      - ./.envs/.local/.postgres
    networks:
      default:
        ipv4_address: 144.xxx.xxx.4

networks:
  default:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
      ipam:
        driver: default
        config:
          - subnet: 144.xxx.xxx.0/24

我认为我必须使用 "docker run" 但两者都不起作用。

编辑: 关键是,我使用了网络 "Driver",因为我从地理定位设备接收到跟踪,我需要使用 Node.js 解析此跟踪并将其发送到 Django。如果我没有设置网络并将 ipv4_address 分配给 Django,则 Django 和 Node.js 之间的连接不起作用。

您提到您已打开端口并将其从路由器转发到笔记本电脑。 您的 docker yaml 不需要知道 public IP,因此您应该删除网络设置并执行以下操作:

Internet > (public IP) Router (NAT to Local Docker host machine IP) > Docker host laptop (with firewall off, or port open) > docker engine (port is mapped from host to container)  > your Node.js script listening to on the port.