2.3.1.5 Kernel UTS Namespace
A focused guide to Kernel UTS Namespace, connecting core concepts with practical Docker and container operations.
The kernel UTS namespace isolates a container's hostname and NIS domain name, giving each container its own identity in this respect, independent of the host's actual hostname and independent of any other container's hostname running on the same machine.
Why Hostname Isolation Matters
Many applications use the system hostname for logging, for generating identifiers, or for distinguishing instances in a clustered setup. Without UTS namespace isolation, every container on a host would report the same hostname as the host itself, making it harder to distinguish log output or metrics coming from different containers.
docker run --rm --hostname myapp-instance alpine hostname
This reports the hostname assigned specifically to this container, distinct from the actual host machine's hostname.
Default Hostname Behavior
If no hostname is explicitly specified, Docker assigns the container's own generated identifier as its hostname by default, which is still distinct from the host's hostname, maintaining the same isolation even without explicit configuration.
docker run --rm alpine hostname
This typically reports a short, container-specific identifier rather than the host's actual hostname.
Setting a Custom Hostname
A container's hostname can be explicitly set to anything meaningful for the application running inside it, which is useful when an application is hostname-aware and expects to identify itself a particular way.
docker run -d --hostname db-primary postgres:16
Sharing the Host's UTS Namespace When Needed
In specific situations, a container can be configured to share the host's UTS namespace rather than having its own, which is occasionally used for tools that genuinely need to observe or report the host's actual hostname rather than an isolated one.
docker run --uts=host alpine hostname
Why UTS Namespace Isolation Matters
UTS namespace isolation is a small but meaningful part of giving each container its own distinct system identity, supporting use cases ranging from clearer log attribution to applications that rely on hostname-based configuration or clustering logic.