Interview Prep/Docker/Networking and Compose

Expose container port range dynamically and discover the mapping.

BeginnerScenarioNetworking and Compose
Answer

Situation read → Several instances on one host, avoiding port clashes.

What I'd do →

docker run -d -p 8080 myapp          # random host port
docker port <container> 8080

Or -P to publish all EXPOSEd ports to random ports.

Why → EXPOSE is documentation only; -p/-P actually publishes.

Interview tip → A common trick question.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose