Networking

In this lesson, you will learn how to use the EXPOSE instruction for documenting which ports should be redirected to the outside world by someone using your image.

When your image hosts server software, it listens on one or several ports. For instance, an HTTP server generally listens on the TCP port 80.

You can make this explicit using an EXPOSE instruction:

Using this instruction is purely for documentation purposes. It will NOT open a port to the outside world when a container is created from that image. Anyone who creates a container will need to explicitly bind that port to an actual port of the host machine using the -p switch of the docker run command. In case you forgot, this is what we saw in the Listening for Incoming Network Connections section.

Why use the EXPOSE instruction then? Again, it is only for documentation purposes; it enables someone who wants to run a container from your image to know which ports they should redirect to the outside world using the -p switch of the docker run command.


Let’s end this discussion in the next lesson.

Storage
Learning More
Mark as Completed
Report an Issue