Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use --hostname in docker?

Tags:

docker

Is --hostname like a domain name system in docker container environment that can replace --ip when referring to other container?

like image 866
letthefireflieslive Avatar asked Mar 26 '17 16:03

letthefireflieslive


People also ask

What is the hostname of a container?

In the same way, a container's hostname defaults to be the container's ID in Docker. You can override the hostname using --hostname . When connecting to an existing network using docker network connect , you can use the --alias flag to specify an additional network alias for the container on that network.

What is a host or container host in Docker?

The docker host is the base traditional OS server where the OS and processes are running in normal (non-container) mode. So the OS and processes you start by actually powering on and booting a server (or VM) are the docker host. The processes that start within containers via docker commands are your containers.

How do I find Docker hostname?

Your answer You can find the manager hostname using the docker node ls command.


2 Answers

The --hostname flag only changes the hostname inside your container. This may be needed if your application expects a specific value for the hostname. It does not change DNS outside of docker, nor does it change the networking isolation, so it will not allow others to connect to the container with that name.

You can use the container name or the container's (short, 12 character) id to connect from container to container with docker's embedded dns as long as you have both containers on the same network and that network is not the default bridge.

like image 143
BMitch Avatar answered Oct 06 '22 07:10

BMitch


--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.

docker run --hostname test --ip 10.1.2.3 ubuntu:14.04  

The following command will create a docker container with base image as ubuntu-14.04 with hostname as test and container ip address as 10.1.2.3

like image 37
shahin Avatar answered Oct 06 '22 08:10

shahin