Is it possible to change or customize the app container's hostname?
search cancel

Is it possible to change or customize the app container's hostname?

book

Article ID: 418510

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry

Issue/Introduction

In Cloud Foundry, every application instance runs inside a container, and each container is assigned a hostname that plays a critical role in networking, routing, and service discovery. By default, hostnames are automatically generated and managed by the platform to ensure uniqueness and consistency.However, there are scenarios where developers or operators may would like to change or customize the container’s hostname to align with organizational standards, simplify debugging, or integrate with external systems.

Environment

Elastic Application Runtime

TAS for VMs

Resolution

Unfortunately, the answer is no. The hostname is the value of INSTANCE_GUID and is generated automatically.

We can see the hostname is hard coded as the value of containerSpec.Handle, which is nothing but a unique identifier string for the container.

https://github.com/cloudfoundry/guardian/blob/2aa1bb7cf2d8f894ecc3566ea4e2115db5af1001/gardener/gardener.go#L296

 desiredSpec := spec.DesiredContainerSpec{
Handle:     containerSpec.Handle,
Hostname:   containerSpec.Handle,
Privileged: containerSpec.Privileged,
Env:        containerSpec.Env,
BindMounts: append(containerSpec.BindMounts, networkBindMounts...),
Limits:     containerSpec.Limits,
BaseConfig: runtimeSpec,
}
 
The containerSpec.Handle is empty during creation stage and is generated automatically as a guid. 
func (g *Gardener) Create(containerSpec garden.ContainerSpec) (ctr garden.Container, err error) {
if containerSpec.Handle == "" {
containerSpec.Handle = g.UidGenerator.Generate()
}