To change the hostname of a running container, you can use the "nsenter" command. You will have to be root on the host, though.
We can list the namespaces on the host with the "lsns" command:
# lsns
NS TYPE NPROCS PID USER COMMAND
4026531836 pid 73 1 root init
4026531837 user 101 1 root init
4026531838 uts 73 1 root init
4026531839 ipc 73 1 root init
4026531840 mnt 72 1 root init
4026531857 mnt 1 14 root kdevtmpfs
4026531957 net 73 1 root init
4026532300 mnt 28 1785 root /usr/bin/python /usr/local/bin/supervisord -c
4026532301 uts 28 1785 root /usr/bin/python /usr/local/bin/supervisord -c
4026532302 ipc 28 1785 root /usr/bin/python /usr/local/bin/supervisord -c
4026532303 pid 28 1785 root /usr/bin/python /usr/local/bin/supervisord -c
4026532305 net 28 1785 root /usr/bin/python /usr/local/bin/supervisord -c
The ones with pid 1785 are my docker container. The namespace type that handles hostnames is "uts", so let's run hostname in that namespace:
# nsenter --target 1785 --uts hostname foo
Now "hostname" in your container should yield "foo"!