Quiz Entry - updated: 2026.11.10
What does the EXPOSE instruction in a Dockerfile actually do?
Nothing on the network: it is documentation that the app listens on that port. The port is only reachable from outside once it is published with -p (or -P) at docker run.
EXPOSE 80 records in the image's metadata that the application inside uses port 80. It does not open a firewall rule, forward a port or bind anything on the host. It serves:
- as documentation for whoever runs the image (
docker image inspectshows it); - as the list of ports that
docker run -P(capital P) publishes to random high host ports.
To actually reach the app from the host you still need -p hostport:containerport, for example -p 8080:80. Conversely, a container can listen on a port that was never exposed, and -p works for it all the same. Containers on the same Docker network can reach each other's ports directly, exposed or not.
Go deeper:
Docker Docs: Dockerfile reference, EXPOSE โ the official statement that EXPOSE does not publish the port.