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.
- EXPOSE 80/tcp
- EXPOSE 80/udp
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.