Doubt_Setting a container hostname

Hello @mmumshad, In the lecture of ’ Setting a container hostname’ *

**docker run container --hostname command has been used to set the hostname.

So I want to know can I login into the container and then change the hostname there ?


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:

Hello @mmumshad ,

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.

Please assist.

Thanks ,

Hello, @sujal.kumar.mitra
You can see the error by running the docker logs <container-id> command.

Resolved by doing

docker container run -itd --name=nginx-container --privileged nginx