ClosedWhen to use --hostname in docker?

455    Asked by EmaHarada in Tableau , Asked on Jul 5, 2021

Does --hostname act as a domain name system? When referring to other containers can it replace --ip?  

 This flag, --hostname is used to change the host name of you container, its used when you run your container.

Example :

  $ docker run --hostname demo nginx

This does not change the container's DNS outside docker and it also does not provide any network isolation, so you cannot connect to the container using the hostname.

Where as the --ip flag is used to assign a specific ip to your container .

Example :

  $ docker run --ip 10.0.0.2 nginx

Hope this helped :smile:

Note: What does Docker hostname do?

--hostname is a parameter which can be given along with docker run command which will set the specified name as containers hostname whereas --ip is parameter to set specific ip address(ipv4) to that particular container.



Your Answer

Interviews

Parent Categories