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 port80
on the container for TCP traffic.EXPOSE 80/udp
: This instruction exposes port80
on the container for UDP traffic.
People Also Ask |
|
---|---|
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.
Contact Us