6.3.2.3 TCP Port Publishing
A focused guide to TCP Port Publishing, connecting core concepts with practical Docker and container operations.
TCP port publishing is the default protocol used by docker run -p, appropriate for the large majority of typical network services — web servers, databases, APIs — that communicate over TCP rather than UDP.
Publishing a TCP Port
Without specifying a protocol explicitly, a published port defaults to TCP, which is correct for most common services.
docker run -d -p 8080:80 nginx:alpine
This is equivalent to explicitly specifying TCP, since it is the implicit default protocol.
Explicitly Specifying TCP
The protocol can also be stated explicitly, which can improve clarity even though it matches the default behavior.
docker run -d -p 8080:80/tcp nginx:alpine
Why Most Services Use TCP
TCP's connection-oriented, reliable delivery model suits most application protocols — HTTP, database wire protocols, most custom application protocols — which generally require reliable, ordered delivery of data, making TCP the natural default choice for port publishing.
docker run -d -p 5432:5432 postgres:16
PostgreSQL's wire protocol, like most database protocols, relies on TCP for reliable communication between client and server.
Verifying a TCP Port Mapping Works
Testing connectivity to a published TCP port confirms the mapping is functioning correctly.
curl http://localhost:8080
A successful response confirms the TCP port mapping correctly connects to the application listening inside the container.
Why TCP Port Publishing Matters
Because the overwhelming majority of containerized services communicate over TCP, understanding TCP port publishing (even as the unstated, implicit default) covers the vast majority of everyday port publishing needs, with UDP publishing reserved for the smaller set of services that specifically require it.