What is the difference between `EXPOSE`, `-p` and `-P`?

BeginnerConceptNetworking
Answer

EXPOSE documents ports in the image. -p host:container publishes a specific mapping. -P publishes every exposed port to a random ephemeral host port. Only publishing makes the service reachable from outside the Docker network.

All Docker questions Roadmap: Docker & containers

More on Networking