Is there a way to add a hostname to an EXISTING docker container?

后端 未结 3 655
傲寒
傲寒 2021-01-07 06:50

I have some containers that communicate via their IP from the network docker.

I can use the option -h or --hostname when running a new cont

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 07:23

    One way is to create network and add different container in this network. When adding container in the network, you can use the --alias option of docker network. Like this:

    • Create a network:

      docker network create  
      
    • Add containers in the network:

      docker network connect --alias   
      docker network connect --alias   
      docker network connect --alias   
      
    • Enjoy.

    So each container can see other container by the alias (the alias is used as hostname).

提交回复
热议问题