Error while changing hostname inside docker container
hostnamectl set-hostname test.ovirt.org
But it gives me back a traceback of
Could not set property: Failed to execute program /lib64/dbus-1/dbus-daemon-launch-helper: Success
with an exit code of 1.
Here is the relevant travis-CI build traceback
I am running the command to change the hostname inside an ansible task inside Travis build. Editing the hostname using an interactive mode wouldn’t be an option.
One Solution collect form web for “Error while changing hostname inside docker container”
If you are looking to name the container as per your requirement you can make use of argument –hostname while running the container.
# docker run --hostname=my-server -it ubuntu:15.0 /bin/bash root@my-server:/# hostname my-server root@my-server:/#
EDIT1 : As you need to change during the runtime, container needs to have root privileges to change the hostname. By default Docker containers will have limited root permissions.
When you try to change the hostname following error may occur saying that you should have root permissions:
# docker run -it ubuntu:15.0 /bin/bash root@92b712251220:/# hostname 92b712251220 root@92b712251220:/# hostname new-server hostname: you must be root to change the host name root@92b712251220:/#
When you run the same container with –privileged option which means running the container with all the root privileges, you will be able to change the hostname:
# docker run -it --privileged ubuntu:15.0 /bin/bash root@08c70ab0c9e3:/# hostname new-server root@08c70ab0c9e3:/# hostname new-server root@08c70ab0c9e3:/#
Ideally it is not the best practise to run the container with –privileged option which gives full control of host machine which is not secured.