有没有办法将主机名添加到EXISTING docker容器? [英] Is there a way to add a hostname to an EXISTING docker container ?
问题描述
我在运行新容器时可以使用-h或--hostname选项,但是想要为现有的contenair设置主机名。
可以吗?
一种方法是在此网络中创建网络并添加不同的容器。
在网络中添加容器时,可以使用docker网络的 - 别名选项。像这样
- 创建一个网络
docker network create< my-network-name>
- 在网络
docker network connect --alias< hostname-container-1> <我的网络系名称> < container-1>
docker network connect --alias< hostname-container-2& <我的网络系名称> < container-2>
docker network connect --alias< hostname-container-3> <我的网络系名称> < container-3>
- 享受你的自我
所以每个容器都可以通过别名看到别的容器(别名被用作主机名)。
I have some conteneur that communicate via their IP from the network docker.
I can use the option -h or --hostname when runnning a new container but I want to set the hostname for existing contenair.
Is it possible ?
One way is to create network and add different container in this network. When adding container in the network, you can use the option --alias of docker network. Like this
- Create a network
docker network create <my-network-name>
- Add containers in the network
docker network connect --alias <hostname-container-1> <my-network-name> <container-1>
docker network connect --alias <hostname-container-2> <my-network-name> <container-2>
docker network connect --alias <hostname-container-3> <my-network-name> <container-3>
- Enjoy your self
So each container can see other container by the alias (the alias is used as hostname).
这篇关于有没有办法将主机名添加到EXISTING docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!