What is the Docker Command to Expose Multiple Ports

To expose multiple ports in a Dockerfile, you can use the EXPOSE instruction followed by the port numbers and their corresponding protocols. Here’s an example:

FROM ubuntu:latest
EXPOSE 80/tcp
EXPOSE 80/udp

This Dockerfile starts with the ubuntu:latest base image. It then exposes two ports, 80/tcp and 80/udp, using the EXPOSE instruction.

  • EXPOSE 80/tcp: This instruction exposes port 80 on the container for TCP traffic.
  • EXPOSE 80/udp: This instruction exposes port 80 on the container for UDP traffic.

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.

Similar Reads

What is the difference between “expose” and “publish” in Docker?

Feature Expose Publish Purpose Specifies ports exposed from the container to the container network Maps container ports to specific host ports for external access Usage Exposes ports within the container network for inter-container communication Maps container ports to host ports for external access Scope Limited to the container network Allows access from outside the container network Configuration Defined in Dockerfile using EXPOSE directive Defined at runtime with -p or –publish option Visibility Ports are visible to other containers in the same network Ports can be accessed from the host machine and external systems...

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...

What Is Docker Expose Port?

Docker “expose” port is a way to specify which ports within a Docker container should be accessible to other containers or the host system. It does not actually publish the ports to the host system or make them accessible outside the container. Instead, it serves as a documentation mechanism to indicate which ports are intended to be used for communication between Docker containers....

Publishing and EXPOSE Docker Ports

Follow the below steps to implement the EXPOSE instruction in a docker container:...

What is the Docker Command to Expose Multiple Ports

To expose multiple ports in a Dockerfile, you can use the EXPOSE instruction followed by the port numbers and their corresponding protocols. Here’s an example:...

Conclusion

To conclude, in this article, we discussed how to use the EXPOSE instruction inside a Dockerfile to expose ports of a Container using a specified protocol and use -p flag to publish the ports....

What does Docker expose do? – FAQ’s

What does Docker expose do?...

Contact Us