2

I cannnot use network_mode: host in docker in windows 10. I try difference images, it cannot too.

I post my docker-compose.yaml below.

docker-compose.yaml

  homeassistant2:
    container_name: hass2
    image: homeassistant/home-assistant:0.112.2
    network_mode: host

But when set the port mapping,everthing is fine

   ports:
      - '8123:8123'
   # network_mode: host

My environmet is windows 10

I get some information from command docker inspect

I post some of it about network settings below.

        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "f084a1e7e4966f0bff678e4120c1bcbc7afdd1c55d5164b1dc4a606470c43bcc",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/default",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "656b532cdc48c9e34e616ec0a38ef944c5e52e2dfca506ca99e53b4b16206000",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

If I need provide something else to analyze the problem, please tell me.

david liu
  • 21
  • 5

1 Answers1

6

When running Docker under Windows or MacOS, you're actually running Docker in a Linux virtual machine. When you set network_mode: host, you're connecting the container to the network environment of the virtual machine. This is seldom going to be useful.

network_mode: host is really only going to make sense when running Docker natively on Linux.

You're better off sticking with port publishing.

larsks
  • 277,717
  • 41
  • 399
  • 399