Search code examples
dockerhostname

Set the hostname of the host from WITHIN a docker container


I realize this is an unusual question but for systems like moby/linuxkit where everything runs within a docker container it seems like it might be needed.

I want to (from within a docker/containerd cotnainer) set the host's hostname.

My usecase stems from loading the hostname/network settings from VMWare guestinfo at boot time.

I can already set up networking for the host in the container, but I cannot seem to figure out how to set the hostname.

I've tried '--privileged', I've tried '--cap SYS_ADMIN'. I am sure there is a way I'm just not sure.

Any ideas?


Solution

  • Okay, this is actually quite simple to do:

    docker run --uts=host ...

    Needs to be running in the same namespace as host.