@sujal.kumar.mitra
Yes, you can do that but, the container needs to have root privileges to change the hostname. By default, Docker containers will have limited root permissions. And to fix this you can run the container with --privileged option which means running the container with all the root privileges, and in this case, you will be able to change the hostname:
While tried to run the command docker container run -itd --name=nginx-container nginx --privileged , the container exited within few seconds , also tried to stop the container and tried to get into the container it is showing that container is not running.