beginnerDocker Networking: Bridge, Host, Overlay, DNS & Port Mapping

What is the difference between EXPOSE and -p in terms of networking?

EXPOSE only documents which port the application listens on inside the image/container — it creates no actual network rule and has no effect on reachability. -p (or --publish) is what actually creates the iptables NAT rule making a container port reachable from outside, whether or not EXPOSE was declared.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is an overlay network and why does it matter for clustering?← Back to all Docker questions