Reputation: 419
I am new to docker, i am using docker version 1.12. I am trying to modify the hostname of a running container, however the hostname command returns hostname: you must be root to change the host name . Is there any way to achieve that after running the container and not in the docker run command?
Upvotes: 6
Views: 17010
Reputation: 21
By following Below Steps you can set after start/run the container.
1.Stop container and service
sudo docker stop CONTAINER_NAME
sudo service docker stop
2.Edit config file (JSON) [You should always make backup first]
/var/lib/docker/containers/CONTAINER_ID/config.json
Replace
"Hostname":"WHATEVER"
with
"Hostname":"NEW_HOSTNAME"
3.Start container and service
sudo service docker start
sudo docker start CONTAINER_NAME
Upvotes: 2
Reputation: 2957
Some discussions here: https://github.com/docker/docker/issues/8902
What I got from above discussion is
add SYS_ADMIN
cap when run the container:
https://github.com/docker/docker/issues/8902#issuecomment-218911749
use nsenter
https://github.com/docker/docker/issues/8902#issuecomment-241129543
Upvotes: 5