April 02, 2017

Exposing Ports

Exposing Ports

Exposing a container port enables the container to accept incoming connections on that port, e.g. the web service container listening on port 80. Use the EXPOSE instruction in the Dockerfile or the --expose option at runtime to expose a port. Docker will only route traffic to exposed ports.
  • The EXPOSE instruction informs Docker that the container listens on the specified network port(s) at runtime, e.g. EXPOSE 80 443 indicates the the container listens for connections on two ports: 80 and 443
  • EXPOSE does not make the ports of the container accessible to the host
    • To do that, you must use either the -p flag to publish a range of ports or the -P flag to publish all of the exposed ports
  • Use the command line option --expose to expose a port or a range of ports at runtime

  • This telnet command allows us to confirm that the container is listening for (HTTP) connections at port 80:

  • With EXPOSE instruction or --expose command line option, ports are only exposed to the container IP. To expose a container to the external world, publish the port via the -p or -P runtime options.

No comments:

Post a Comment