Docker Community Forums

Share and learn in the Docker community.

Does the EXPOSE instruction expose ports on the host?

No, not automatically. The EXPOSE instruction informs Docker that the container will listen on the specified network ports at runtime. Docker uses this information to interconnect containers using links and to determine which ports to expose to the host when using the -P flag.

Note: EXPOSE doesn’t define which ports can be exposed to the host or make ports accessible from the host by default. To expose ports to the host, at runtime, use the -p flag or the -P flag.

For more information, see https://docs.docker.com/reference/run/#expose-incoming-ports

Docker uses this information to interconnect containers using links and to determine which ports to expose to the host when using the -P flag.

Is this still true with the latest versions of Docker? Linking is now marked as deprecated (except possibly(?) for Docker Compose linking).

What happens if you don’t explicitly EXPOSE a port? Is it just basically used for documenting which port the service is listening on for somebody reading the Dockerfile?