有没有办法将主机名添加到EXISTING docker容器? [英] Is there a way to add a hostname to an EXISTING docker container ?

查看:127
本文介绍了有没有办法将主机名添加到EXISTING docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在运行新容器时可以使用-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆