简体   繁体   中英

How to change the hostname of Ubuntu in docker?

When using Ubuntu in docker , there is no way to modify the hostname; each time to connect to ubuntu, hostname is a random string ....

Docker run

If you are running the container using docker run , then you can use -h option as said by @callmemath

docker run -h custom.hostname -ti ubuntu bash

Docker-compose

If you are running containers using docker-compose then you need to use hostname .

hostname: Any_name_you_like

Use -h option :

docker run -h custom.hostname -ti ubuntu bash
root@custom:/# hostname
custom.hostname

See docker run documentation for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM