[英]How to change the hostname of Ubuntu in docker?
When using Ubuntu in docker , there is no way to modify the hostname;在 docker 中使用 Ubuntu 时,无法修改主机名; each time to connect to ubuntu, hostname is a random string ....每次连接ubuntu,hostname都是一个随机字符串....
If you are running the container using docker run
, then you can use -h
option as said by @callmemath如果您使用docker run
运行容器,那么您可以使用 @callmemath 所说的-h
选项
docker run -h custom.hostname -ti ubuntu bash
If you are running containers using docker-compose then you need to use hostname .如果您使用 docker-compose 运行容器,那么您需要使用hostname 。
hostname: Any_name_you_like
Use -h
option :使用-h
选项:
docker run -h custom.hostname -ti ubuntu bash
root@custom:/# hostname
custom.hostname
See docker run documentation for more details有关更多详细信息,请参阅docker run 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.