Hey everyone! I'm facing a really confusing issue with Docker on my Mac. I thought I understood that when I set `network_mode: host` in my `docker-compose.yaml` file, the `ports` section should be ignored. For example, I have this configuration:
```yaml
services:
web:
image: nginx
network_mode: host
ports:
- 80:80
```
However, when I run this with `docker compose up`, it starts without any errors. But when I try to access `localhost:80`, I get an empty response from cURL.
After troubleshooting for almost two days, I discovered that Docker Desktop reported a port conflict on port 80. Once I removed the `ports` section, accessing the endpoint worked just fine. Also, if I removed `network_mode: host` and just used the `ports`, it worked too.
So my question is, is this a bug with Docker on Mac, or am I missing something important? I don't want to file a bug report prematurely! 😄
1 Answer
You're right about the `network_mode: host` part! When you use the host network mode, it means your container shares the host's network stack, and port mapping isn't necessary or valid. That's why you're seeing port conflicts if you're trying to map it while using the host mode. It’s not a bug, just Docker's expected behavior.

Exactly! Your setup may work differently on Windows or Linux, where host network mode is handled differently. Just keep that in mind while using Docker on Mac!