I have created a program in debug mode which uses port 5020. In debug mode, the code worked fine, but when I put the code in release mode, the port is not exposed.
Below is the docker-compose.yml file:
Does anyone have an idea why the port is shown in debug mode but not in release mode?
The issue is you have both
network_mode: host and
ports: defined at the same time. These two options do not make sense together. When you expose a port with
ports: you’re asking to expose a port from this container’s network stack and link it to a port on the host network stack. But, you have
network_mode: host, which makes it so that your container runs on the host network stack. Therefore the concept of exposing a port doesn’t make sense anymore, your container is on the host network stack there’s nothing to expose.
There’s a note about this behavior on Docker’s documentation: Host network driver | Docker Documentation
Now as for why this worked in debug mode, I’m not sure. Maybe in debug mode the container wasn’t actually running with host networking? Maybe your application wasn’t meant to run on the host networking stack? It’s hard to say without knowing more here.
Hello @xAnouk ,
Do you have any updates on this topic?