Shenhai Gan
Shenhai Gan

Reputation: 31

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 ....

Upvotes: 3

Views: 3609

Answers (2)

Ayushya
Ayushya

Reputation: 10447

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

Upvotes: 4

6be709c0
6be709c0

Reputation: 8461

Use -h option :

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

See docker run documentation for more details

Upvotes: 2

Related Questions