Why does Docker on Mac show no errors with ports defined when using host network mode?

July 13, 2025 2 answers
Asked by 72rpm turntable
Hey everyone! I've been trying to figure out a problem with my Docker setup on MacOS. I've got this `docker-compose.yaml` file where I defined a service like this: ```yaml services: web: image: nginx network_mode: host ports: - 80:80 ``` From my understanding, when `network_mode: host` is set, the `ports` section should be ignored because it directly maps the container ports to the host network. But when I run `docker compose up` from the terminal, there are no error messages, and everything seems to start just fine. However, when I try to access `localhost:80`, I get an empty response from cURL. After two days of poking around, I discovered a port conflict on port 80 through Docker Desktop. Once I removed the `ports` line, I could access the service using cURL without an issue. If I take out `network_mode: host` and use `ports` instead, it works as well. My question is, is this a bug in Docker, or am I missing some important detail? I hesitate to report it as a bug without being sure. Any help would be greatly appreciated!

Answers

2hrBookbinding
It does seem like Docker could give a better warning about this! Youโ€™re not missing anything; itโ€™s just how Docker is set up. If you're using `network_mode: host`, you shouldn't need the `ports` mapping at all. Itโ€™s good you figured out the port conflict issue. Just remember, using the `host` mode can lead to some tricky scenarios, especially with port conflicts. Always check your running services to avoid collisions!
Reply to this answer
_census_notes
Youโ€™re right that port mapping doesnโ€™t work with `network_mode: host`. When you set that mode, the container's ports are accessible on the host directly, so Docker skips mapping them. The lack of error messages can be confusing, but it's how Docker is designed to work. Just make sure you're not trying to map the same port across different containers if you're using host mode, as this can lead to the conflicts you noticed.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions