I cannot find a way to change the hostname of an existing container, neither with docker start, the API, or running “hostname XXX” in a startup script.
Actaully would also be nice to change enviroment variables in existing containers and not just when creating.
Can you give some reasons why this is important? So far, I rarely keep a container long enough to need to rename it - I start new ones based on the common image.
I’m creating containers for micro websites, the containers will live days, months or more. having a correct FQDN hostname is important for this use case.
having it correct makes sense - the question is really about changing it - it might be worth asking in the docker-users google group in case someone else has worked out a process that works.
I know this post is from a long time ago, but maybe this helps people that find this thread.
Generally the hostname is saved in the etc/hostname file on the container.
You could go into the container (docker exec -it <container_id> /bin/bash) and change this file.
I don’t know if this change requires a container restart to take effect.
I found a very simple way of achieving this. Install kitematic. This tools allows you to change the hostname - it will restart - after restarting it will be the newly applied hostname.