I cannot find port in host network

docker desktop version: 4.30.0 (149282)

then enable host networking

docker-compose.yml:

services:
  nacos:
    image: nacos/nacos-server:latest
    container_name: nacos-standalone
    expose:
      - 8848
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
    volumes:
      - ./standalone-logs/:/home/nacos/logs
    restart: always
    network_mode: host

but lsof -i:8848 output nothing

then enter container , run netstat -tlnp, only ipv6 port listening
other container such as nginx can find port on machine, nginx is both listening on ipv4,ipv6

I guess the ports of the springboot project cannot be mapped.
so, is there a solution? or is bug?

Do you have connection error as well, or just want to list used ports? You will never have real host networking in Docker Desktop as that is physically not possible. What Docker Desktop does is forwarding ports from the host to the virtual machine and from the container to the host. The documentation shows the limitations of the host network feature:

https://docs.docker.com/network/drivers/host/#docker-desktop

Limitations

  • The host network feature of Docker Desktop works on layer 4. This means that unlike with Docker on Linux, network protocols that operate below TCP or UDP are not supported.
  • This feature doesn’t work with Enhanced Container Isolation enabled, since isolating your containers from the host and allowing them access to the host network contradict each other.
  • IPv6 is not yet supported. Services need to use IPv4 and bind to address 127.0.0.1 in the container to be visible on the host.
1 Like