Docker run command by default uses a dedicated UTS namespace for the container and because of it the container gets its own/unique hostname. I am trying to share the UTS namespace between two containers but it seems that it is not possible with docker run command.
Following are the commands that I ran -
docker run -d --name container1 alpine sleep infinity
docker run -it --name container2 --uts container:container1 alpine /bin/sh
Error -
docker: --uts: invalid UTS mode.
Based on the documentation, it looks like it is not possible to reference a container with the --uts flag. This is not the case with other namespace related flags like --pid, --network, etc. They support referencing other containers. Why "container:<name|id>” mode is not supported by the --utc flag? How to share UTS namespace between containers so that they share hostname?
I don't know how to share UTS namespace between containers. But, if your final aim is just to share
hostname
between containers, next should work if you not care about network share:It let
container2
use the same network ofcontainer1
, refers to this. FYI in case this help.Another way maybe just expose
/etc/hostname
tobind mounts
orvolume
, and let all containers which you needed to use the same one, then you no need to share net.