Node.js › Docker & Deployment
What does the EXPOSE instruction in a Dockerfile actually do, and what is a common misconception about it?
BeginnerAnswer
EXPOSE is purely documentation -- it declares which port(s) the containerized application listens on, informing anyone reading the Dockerfile or using tools that introspect it, but it does not actually publish or open that port to the host machine; a common misconception is that EXPOSE alone makes a service reachable, when actually the '-p' flag on 'docker run' (or the 'ports' section in Docker Compose) is what performs the actual port mapping to the host.
# Documents that the app listens on 3000, but doesn't publish it
EXPOSE 3000
# Actual port mapping happens at run time
# docker run -p 3000:3000 myappReal-world example A developer confused why they couldn't reach their containerized app despite an EXPOSE 3000 line in the Dockerfile discovers they'd forgotten to add the corresponding '-p 3000:3000' flag to their 'docker run' command, which is the step that actually maps the container's port to the host.