Miguel Herreros Cejas
Miguel Herreros Cejas

Reputation: 674

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

I have a Docker Node.js container listening port 4757 with NET library, using my Public IP.

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

When I access from my computer I do not have problem, but If I try to access to my mobile or other device the connection is refused (ERR_ADDRESS_UNREACHABLE).

The application worked correctly by docker-composer in other laptop, the problem is in my new laptop. It is my 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

I think that I have to use "docker run" but not working neither. Docker - Make docker containers use my public ip

EDIT: The point is, I used a Network "Driver" because I receive traces from a geolocation device and I need parser this trace with Node.js and send it to Django. If I not set a Network and assign a ipv4_address to Django the connection between Django and Node.js not working.

Upvotes: 0

Views: 1845

Answers (1)

Bouzid Zitouni
Bouzid Zitouni

Reputation: 1339

You mentioned that you have the port open and forwarded from your router to your laptop. your docker yaml doesn't need to know about the public IP, so you should remove the network settings and go for some thing like:

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.

Upvotes: 1

Related Questions