expose
command?The expose
command is used to make a Docker container bind and listen on a specific port. It is up to the user to decide whether they want to listen on a TCP or a UDP connection – the connection is TCP by default. The user can then specify the reliability protocol by adding either /tcp
or /udp
after the port number.
# Exposes port 80 using TCP protocol
EXPOSE 80
# OR
EXPOSE 80/tcp
# Exposes port 80 using UDP protocol
EXPOSE 80/udp
The user has three options when running a Docker container:
The user restricts the communication with the container from within the container only. This approach is adopted by the user if the container at hand is running isolated from all the other containers.
The user restricts the communication with the container from within the Docker. It helps to establish inter-container communication in Docker.
After publishing(-p
) the container, the user allows communication with the container from outside the Docker.
To publish a container, use the
-p
flag with therun
command.