beginnerDockerfile Instructions & Multi-Stage Builds

Does EXPOSE actually publish a port?

No. EXPOSE is documentation/metadata recorded in the image — useful for tools and humans reading the Dockerfile, and used by docker run -P (publish all exposed ports to random host ports). Actually making a port reachable from outside the container requires -p hostPort:containerPort at docker run or a ports: entry in Docker Compose.

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 Why should you use exec form instead of shell form for ENTRYPOINT/CMD?← Back to all Docker questions