Expose all ports for a Docker image

Using host networking will expose almost all the ports just like you're running the application in the host machine. If port flags are used when running in host networking mode, those flags are ignored with a warning

Note: Given that the container does not have its own IP-address when using host mode networking, port-mapping does not take effect, and the -p, --publish, -P, and --publish-all option are ignored, producing a warning instead:

WARNING: Published ports are discarded when using host network mode

Make sure your host is a Linux host because host networking is only supported by Linux hosts.

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

This is mentioned in Docker documentation it self. View particular Documentation


When running using --network host there is no need to map the ports. All the docker container ports will be available since the network host mode makes the container use the host's network stack.

Also the EXPOSE 8080 61616 5672 61613 5445 1883 is not needed. This instruction doesn't do anything. It is just a way to document which ports need to be mapped.

In short, running docker run --network host ... will expose all the container ports.


The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

More information on the Docker documentation portal.

Tags:

Docker