The EXPOSE
instruction informs Docker that the container listens on the specified network ports at runtime. i.e, It helps in inter-container communication. You can specify whether the port listens on TCP or UDP, and the default is TCP.
EXPOSE <port> [<port>/<protocol>...]
EXPOSE 80
EXPOSE 80/udp
EXPOSE 80/tcp
Note: To use both TCP and UDP, you need to include two instructions.
But if you want to bind the port of the container with the host machine on which the container is running, use -p
option of docker run
command.
docker run -p <HOST_PORT>:<CONTAINER:PORT> IMAGE_NAME
docker run -p 80:80/udp myDocker