Windows Docker, `network_mode: host` connection problem

When I use network_mode: bridge with ports: - "8123:8123" it works on:
http://localhost:8123, http://127.0.0.1:8123 and http://192.168.0.87:8123
But when I use network_mode: host neither one works Unable to connect, can’t establish a connection to the server the weird thing is, right before making this post it did connect but then showed an error unable to connect to home assistant., now it doesn’t do that.
Here is my system info:

OS: Windows 11, 23H2, build: 22631.2861
WSL2, Ubuntu-22.04
Docker Desktop 4.26.1 (131620)

Here is docker-compose.yml:

services:
  homeassistant:
    container_name: ha
    image: ghcr.io/home-assistant/home-assistant:stable
    privileged: true
    network_mode: host
    restart: unless-stopped
    volumes:
      - 'C:\homeassistant:/config'
    environment:
      - TZ=Europe/Bucharest

Here is the ipconfig output:

Wireless LAN adapter Local Area Connection* 12:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 15:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7c6:40b3:f965:410f%20
   IPv4 Address. . . . . . . . . . . : 192.168.0.87
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::9ac2:2a40:d058:f970%13
   IPv4 Address. . . . . . . . . . . : 169.254.123.31
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::6d07:c255:65a1:fd02%21
   IPv4 Address. . . . . . . . . . . : 172.28.208.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL (Hyper-V firewall)):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::d9f0:41b2:8d05:76d9%34
   IPv4 Address. . . . . . . . . . . : 172.23.208.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Container logs:

2023-12-29 22:18:47 s6-rc: info: service s6rc-oneshot-runner: starting
2023-12-29 22:18:47 s6-rc: info: service s6rc-oneshot-runner successfully started
2023-12-29 22:18:47 s6-rc: info: service fix-attrs: starting
2023-12-29 22:18:47 s6-rc: info: service fix-attrs successfully started
2023-12-29 22:18:47 s6-rc: info: service legacy-cont-init: starting
2023-12-29 22:18:47 s6-rc: info: service legacy-cont-init successfully started
2023-12-29 22:18:47 s6-rc: info: service legacy-services: starting
2023-12-29 22:18:47 services-up: info: copying legacy longrun home-assistant (no readiness notification)
2023-12-29 22:18:47 s6-rc: info: service legacy-services successfully started

Container Inspect:

{
	"Id": "57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d",
	"Created": "2023-12-29T20:18:46.851684891Z",
	"Path": "/init",
	"Args": [],
	"State": {
		"Status": "running",
		"Running": true,
		"Paused": false,
		"Restarting": false,
		"OOMKilled": false,
		"Dead": false,
		"Pid": 3992,
		"ExitCode": 0,
		"Error": "",
		"StartedAt": "2023-12-29T20:18:47.072615074Z",
		"FinishedAt": "0001-01-01T00:00:00Z"
	},
	"Image": "sha256:003e99ae19b0c68a9cbb0c28e68cf843e12513287d1945c1b0b3d1e0eb246973",
	"ResolvConfPath": "/var/lib/docker/containers/57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d/resolv.conf",
	"HostnamePath": "/var/lib/docker/containers/57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d/hostname",
	"HostsPath": "/var/lib/docker/containers/57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d/hosts",
	"LogPath": "/var/lib/docker/containers/57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d/57dbaa11dd878b5a723196e7d3c82ac8ecddbc08904af68327277b58f9dc4b4d-json.log",
	"Name": "/ha",
	"RestartCount": 0,
	"Driver": "overlay2",
	"Platform": "linux",
	"MountLabel": "",
	"ProcessLabel": "",
	"AppArmorProfile": "",
	"ExecIDs": null,
	"HostConfig": {
		"Binds": [
			"C:\\homeassistant:/config:rw"
		],
		"ContainerIDFile": "",
		"LogConfig": {
			"Type": "json-file",
			"Config": {}
		},
		"NetworkMode": "host",
		"PortBindings": {},
		"RestartPolicy": {
			"Name": "unless-stopped",
			"MaximumRetryCount": 0
		},
		"AutoRemove": false,
		"VolumeDriver": "",
		"VolumesFrom": null,
		"ConsoleSize": [
			0,
			0
		],
		"CapAdd": null,
		"CapDrop": null,
		"CgroupnsMode": "host",
		"Dns": null,
		"DnsOptions": null,
		"DnsSearch": null,
		"ExtraHosts": [],
		"GroupAdd": null,
		"IpcMode": "private",
		"Cgroup": "",
		"Links": null,
		"OomScoreAdj": 0,
		"PidMode": "",
		"Privileged": true,
		"PublishAllPorts": false,
		"ReadonlyRootfs": false,
		"SecurityOpt": [
			"label=disable"
		],
		"UTSMode": "",
		"UsernsMode": "",
		"ShmSize": 67108864,
		"Runtime": "runc",
		"Isolation": "",
		"CpuShares": 0,
		"Memory": 0,
		"NanoCpus": 0,
		"CgroupParent": "",
		"BlkioWeight": 0,
		"BlkioWeightDevice": null,
		"BlkioDeviceReadBps": null,
		"BlkioDeviceWriteBps": null,
		"BlkioDeviceReadIOps": null,
		"BlkioDeviceWriteIOps": null,
		"CpuPeriod": 0,
		"CpuQuota": 0,
		"CpuRealtimePeriod": 0,
		"CpuRealtimeRuntime": 0,
		"CpusetCpus": "",
		"CpusetMems": "",
		"Devices": null,
		"DeviceCgroupRules": null,
		"DeviceRequests": null,
		"MemoryReservation": 0,
		"MemorySwap": 0,
		"MemorySwappiness": null,
		"OomKillDisable": false,
		"PidsLimit": null,
		"Ulimits": null,
		"CpuCount": 0,
		"CpuPercent": 0,
		"IOMaximumIOps": 0,
		"IOMaximumBandwidth": 0,
		"MaskedPaths": null,
		"ReadonlyPaths": null
	},
	"GraphDriver": {
		"Data": {
			"LowerDir": "/var/lib/docker/overlay2/17fbee3e44b09e519cc931b9da462874c705ab7c656b20f137603773849ff2ca-init/diff:/var/lib/docker/overlay2/944bd0eb502df51acd05108b7dcbfcd70f4d1fc4016e3527e278ab729dd1c009/diff:/var/lib/docker/overlay2/fd69d28bd0860ca32ed9c6f074164032e6b59f15068abcad7cd526f5965e41cc/diff:/var/lib/docker/overlay2/d3ff66beeff83052fb255d95574b1308ff1c6d9181d5c09ccfa9acab10a26824/diff:/var/lib/docker/overlay2/a2a6c7a63bc24fe4eb98b8e640780e990d7bbf2d53afcd18917d7e081dfe5fc9/diff:/var/lib/docker/overlay2/c4be764fb0c912975ec6af24a7849c9f07b27280af864a3492085e1f387c94ba/diff:/var/lib/docker/overlay2/1a9d692221e68c4a42c9b9652ddf49787c51015a8adbd5cdb6244ecc269bb3df/diff:/var/lib/docker/overlay2/29d7dd20ec7b893824a7ab346abfe59110429a8412454369d7c92c7f36fd0102/diff:/var/lib/docker/overlay2/a6d03ccca1e44c40729f342fe8322bf7bd843066e96d24121cb7e305923fc916/diff:/var/lib/docker/overlay2/df587d6babc526db2a8a28552b14f99d4d779cbc454ed9fe1f06755ceb52561c/diff:/var/lib/docker/overlay2/64514eb71f346e73b2226d2e80c367837d3850068fc74d32f648573da8e70a6a/diff:/var/lib/docker/overlay2/0718fd81cbceb40e18dacba629271a68059ec975fcc7c5cf69fdc01a71a77d32/diff:/var/lib/docker/overlay2/2fe8811a50d980585905679a22e07e9b713eb13af692f9c0bfb7301366b4937e/diff:/var/lib/docker/overlay2/8353f3c844000c6819c00528ee02d563ea4c6faa12bf45ba89a695661c3d59d9/diff:/var/lib/docker/overlay2/ec3974c90bfbb9777950fe2b710ec2ed14319d61ff781706b2f0861f1d8289e9/diff:/var/lib/docker/overlay2/362b3351a1640be5701c41be394d5d5dc5016a3c1d70ec298bf90d43f16c839b/diff:/var/lib/docker/overlay2/31cc7bc0f4497d3bb7ce555013b41de86fb800cad0b00785f7ba57cdc1f756d7/diff:/var/lib/docker/overlay2/79d2ebea1e171ed9250889794c2b416100fd828857a151b442b0f368aa2cc340/diff:/var/lib/docker/overlay2/6e8a534fd612c58e365936ef611af3b6733fba2642df395e077bbcccd6bbdcb7/diff:/var/lib/docker/overlay2/2840612c5210ef06a046a5d0f04e04eff40f7d98552a2b89e455d1e6908bc225/diff:/var/lib/docker/overlay2/8fd6d482e54d6e747074cc49afe422ced1d31c4168a9a5f93ccc39b8845e2aa4/diff:/var/lib/docker/overlay2/7d60a3986c2ab0127fcf14cc04de0839a2a81214bdb9752b6b06fbf110490d63/diff:/var/lib/docker/overlay2/1315317eeeb747a024e0c9e33949487488ea194c54770bd8a98f0060c5f9bb20/diff:/var/lib/docker/overlay2/b3e094a085d902292bb1828328e64e3bcc5c3362e085e959157e7f9382ab65a5/diff:/var/lib/docker/overlay2/1b35b92b3678d48b18fa1fb69b8fff17b6aa0a262f30d4f052f9551979708b00/diff:/var/lib/docker/overlay2/cd6ab27aa780cff4e3bd58d3d531ee73bf838e7e7a58354c4b55cb303e6322a7/diff:/var/lib/docker/overlay2/d0f77bfee449f73bccc72cf1f89c64d2d206f86e96d115c3842c4725601315ad/diff:/var/lib/docker/overlay2/4406c21374ccfedeeb482993aefb7f5ca7525fe8ce1f907990c7622348392389/diff:/var/lib/docker/overlay2/e83de75a43bdad5ae50095710d71e55a0495ba5022c62b0d7942a03967fbf363/diff:/var/lib/docker/overlay2/e77cdc5208c194c6fe8f9eab2d5054f8ccccd6f531f83f1cf211a53485c64e27/diff:/var/lib/docker/overlay2/d55bd4f9d960c137857492e6f42843484ba18f7871bf4471292426b807f447cf/diff",
			"MergedDir": "/var/lib/docker/overlay2/17fbee3e44b09e519cc931b9da462874c705ab7c656b20f137603773849ff2ca/merged",
			"UpperDir": "/var/lib/docker/overlay2/17fbee3e44b09e519cc931b9da462874c705ab7c656b20f137603773849ff2ca/diff",
			"WorkDir": "/var/lib/docker/overlay2/17fbee3e44b09e519cc931b9da462874c705ab7c656b20f137603773849ff2ca/work"
		},
		"Name": "overlay2"
	},
	"Mounts": [
		{
			"Type": "bind",
			"Source": "C:\\homeassistant",
			"Destination": "/config",
			"Mode": "rw",
			"RW": true,
			"Propagation": "rprivate"
		}
	],
	"Config": {
		"Hostname": "docker-desktop",
		"Domainname": "",
		"User": "",
		"AttachStdin": false,
		"AttachStdout": true,
		"AttachStderr": true,
		"Tty": false,
		"OpenStdin": false,
		"StdinOnce": false,
		"Env": [
			"TZ=Europe/Bucharest",
			"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
			"LANG=C.UTF-8",
			"S6_BEHAVIOUR_IF_STAGE2_FAILS=2",
			"S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0",
			"S6_CMD_WAIT_FOR_SERVICES=1",
			"S6_SERVICES_READYTIME=50",
			"S6_SERVICES_GRACETIME=220000"
		],
		"Cmd": null,
		"Image": "ghcr.io/home-assistant/home-assistant:stable",
		"Volumes": null,
		"WorkingDir": "/config",
		"Entrypoint": [
			"/init"
		],
		"OnBuild": null,
		"Labels": {
			"com.docker.compose.config-hash": "9c99a2b25c2188090ce04ea2a277fd139924fce7723eacf3e024bd85a573f764",
			"com.docker.compose.container-number": "1",
			"com.docker.compose.depends_on": "",
			"com.docker.compose.image": "sha256:003e99ae19b0c68a9cbb0c28e68cf843e12513287d1945c1b0b3d1e0eb246973",
			"com.docker.compose.oneoff": "False",
			"com.docker.compose.project": "homeassistant",
			"com.docker.compose.project.config_files": "C:\\homeassistant\\docker-compose.yml",
			"com.docker.compose.project.working_dir": "C:\\homeassistant",
			"com.docker.compose.service": "homeassistant",
			"com.docker.compose.version": "2.23.3",
			"io.hass.arch": "amd64",
			"io.hass.base.arch": "amd64",
			"io.hass.base.image": "ghcr.io/home-assistant/amd64-base:3.18",
			"io.hass.base.name": "python",
			"io.hass.base.version": "2023.10.4",
			"io.hass.type": "core",
			"io.hass.version": "2023.12.4",
			"org.opencontainers.image.authors": "The Home Assistant Authors",
			"org.opencontainers.image.created": "2023-12-27 10:14:28+00:00",
			"org.opencontainers.image.description": "Open-source home automation platform running on Python 3",
			"org.opencontainers.image.documentation": "https://www.home-assistant.io/docs/",
			"org.opencontainers.image.licenses": "Apache License 2.0",
			"org.opencontainers.image.source": "https://github.com/home-assistant/core",
			"org.opencontainers.image.title": "Home Assistant",
			"org.opencontainers.image.url": "https://www.home-assistant.io/",
			"org.opencontainers.image.version": "2023.12.4"
		}
	},
	"NetworkSettings": {
		"Bridge": "",
		"SandboxID": "1c9657decc3c4689c79eaa1c7ef742ed70c139c9b81aff53b691c02091bab01d",
		"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,
				"MacAddress": "",
				"NetworkID": "e5c4b02c5824fe8247bb0d2849cf5b2a18e8fc67ca7bf4524df63532a6a2854e",
				"EndpointID": "d2ea9606baf23534c937f0b94f444d61897e1c91d3a2ed52596c6379edccce77",
				"Gateway": "",
				"IPAddress": "",
				"IPPrefixLen": 0,
				"IPv6Gateway": "",
				"GlobalIPv6Address": "",
				"GlobalIPv6PrefixLen": 0,
				"DriverOpts": null
			}
		}
	}
}

I want to use the ESPHome devices, and for my understanding I need network_mode: host, is there a way to make it work with bridge or do I need to fix this and use host?

And Happy new year, everyone! I hope you have an awesome year!

Docker on Windows doesn’t support host networking, which is why HA isn’t supported in Docker on Windows.

Run a VM and run HA in the VM.

Thanks for the answer. One more question: Can I use Docker in bridge mode and make it work with an ESP32 that is using ESPHome, code?
Edit: Yes, it’s working, no need for host network.

services:
  homeassistant:
    container_name: ha
    image: ghcr.io/home-assistant/home-assistant:stable
    privileged: true
    restart: unless-stopped
    volumes:
      - 'C:\homeassistant:/config'
    environment:
      - TZ=Europe/Bucharest
    ports:
      - "8123:8123"

  esphome:
    container_name: esphome
    image: ghcr.io/esphome/esphome
    volumes:
      - 'C:\homeassistant\esp-config:/config'
    environment:
      - ESPHOME_DASHBOARD_USE_PING=true
      - TZ=Europe/Bucharest
    restart: always
    privileged: true
    ports:
      - "6052:6052"

Keep in mind that any integration that uses mDNS or other broadcasts won’t work. HA itself will be fine.