When to use --hostname in docker?
Is it --hostname
like a domain name system in a docker container environment that can replace --ip
when accessing another container?
The flag --hostname
changes the hostname inside your container. This may be required if your application expects a specific value for the hostname. It does not change DNS outside of docker and does not change network isolation, so it will prevent others from connecting to a container with that name.
You can use the container name or container (short, 12 characters) to connect from container to container with docker dns built in if you have both containers on the same network and that network is not the default bridge.
--hostname
is a parameter that can be given in conjunction with a command docker run
that sets the specified name as the container name as the container, whereas --ip
is the parameter to set a specific ip address (ipv4) to that specific container.
docker run --hostname test --ip 10.1.2.3 ubuntu:14.04
The following command will create docker container with base image as ubuntu-14.04 with hostname as test and container IP as 10.1.2.3