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

后端 未结 3 649
傲寒
傲寒 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:25

    The hostname is immutable once the container is created (although technically you can modify /etc/hostname).

    As suggested in another answer, you cannot change the hostname by stopping or restarting the container. There are not Docker engine client parameters for the start command that affect hostname. That wouldn't make sense anyway as starting a container simply launches the ENTRYPOINT process in a container filesystem that has already been created (i.e. /etc/hostname has already been written).

    It is possible to synchronize the container hostname with the host by using the --uts=host parameter when the container is created. This shares the UTS namespace. I would not recommend --net=host unless you also want to share the host network devices (i.e. bypass the Docker bridge).

提交回复
热议问题