✦ For everyone, free.

Practical knowledge for real and everyday life

Home

4.2.10.4 EXPOSE Protocol Ports

A focused guide to EXPOSE Protocol Ports, connecting core concepts with practical Docker and container operations.

EXPOSE protocol ports refers to specifying, as part of an EXPOSE declaration, which network protocol — TCP or UDP — a given port uses, since the two protocols are handled differently when a port is eventually published.

Default Protocol Is TCP

When no protocol is specified, EXPOSE assumes TCP, which is correct for the large majority of typical network services.

EXPOSE 8080

This is equivalent to explicitly writing 8080/tcp, since TCP is the implicit default.

Declaring a UDP Port Explicitly

Applications using UDP-based protocols — DNS servers, certain VoIP or streaming protocols — need to declare their ports with the /udp suffix to accurately reflect the protocol in use.

EXPOSE 53/udp
Declaring Both Protocols on the Same Port Number

Some applications use the same port number for both TCP and UDP traffic, serving different purposes on each, which can be declared with two separate EXPOSE instructions.

EXPOSE 53/tcp
EXPOSE 53/udp
Why Protocol Matters When Publishing

When actually publishing a port at run time, the protocol must also be specified correctly, since publishing a port as TCP when the application actually uses UDP (or vice versa) results in the published mapping simply not working for that traffic.

docker run -p 53:53/udp myapp

Explicitly specifying /udp here ensures the port mapping matches the protocol the application actually expects to communicate over.

Verifying Protocol Declarations Match Actual Behavior

Confirming which protocol an application's listening port actually uses, and ensuring the EXPOSE declaration and any corresponding port mapping match that protocol, avoids a subtle and sometimes confusing class of networking issue.

docker exec myapp ss -tulnp

This reveals both TCP (-t) and UDP (-u) listening ports, useful for confirming the declared protocol actually matches reality.

Why Protocol-Aware EXPOSE Declarations Matter

Correctly specifying protocol alongside port number keeps EXPOSE accurate and ensures that any tooling or documentation relying on it does not mislead someone into configuring a port mapping with the wrong protocol.