When to use --hostname in docker?

2019-01-17 21:07发布

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

标签: docker
2条回答
女痞
2楼-- · 2019-01-17 21:33

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

查看更多
男人必须洒脱
3楼-- · 2019-01-17 21:40

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.

查看更多
登录 后发表回答