What Is a Port?
A port is a fundamental element of networking that facilitates communication between different processes or services on a computer or networked device. It acts as a communication endpoint, allowing data to be sent and received across a network. Ports are identified by numeric values and are used to address specific services or applications running on a device. They enable the establishment of connections between clients and servers, enabling the exchange of data. For further insight into ports and their significance in networking, please refer to the following link
The syntax to EXPOSE the ports by specifying a protocol is:
Syntax: EXPOSE <port>/<protocol>
In this article, we are going to discuss some practical examples of how to use EXPOSE instruction in your Dockerfile and overriding it using the publish flag while starting a Docker Container.
Docker – EXPOSE Instruction
The EXPOSE instruction exposes a particular port with a specified protocol inside a Docker Container. In the simplest terms, the EXPOSE instruction tells Docker to get all the information required during the runtime from a specified port. These ports can be either TCP or UDP, but it’s TCP by default. It is also important to understand that the EXPOSE instruction only acts as an information platform (like Documentation) between the creator of the Docker image and the individual running the Container. Some points to be noted are:
- It can use TCP or UDP protocol to expose the port.
- The default protocol is TCP if no other protocol is specified.
- It does not map ports on the host machine.
- It can be overridden using the publish flag (-p) while starting a Container.