Port not exposed in release mode


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:

    depends_on: []
    devices: []
    image: modbusserver_arm64v8-debian-python3_bullseye_release_f98057ea-b612-4bff-854f-9ac723757978
    network_mode: host
    - 5020:5020/tcp
    volumes: []
version: '2.4'

Does anyone have an idea why the port is shown in debug mode but not in release mode?

Kind regards,

Greetings @xAnouk,

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.

Best Regards,

Hello @xAnouk ,
Do you have any updates on this topic?

Best regards,