mirror of
https://github.com/containers/buildah.git
synced 2026-02-05 09:45:38 +01:00
Support the containers.conf container_name_as_hostname option
When containers.conf has the "container_name_as_hostname" option set, use that value, with values that don't fit `[A-Za-z0-9][A-Za-z0-9.-]+` stripped out. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
@@ -586,7 +586,17 @@ func (b *Builder) configureNamespaces(g *generate.Generator, options *RunOptions
|
||||
} else if b.Hostname() != "" {
|
||||
g.SetHostname(b.Hostname())
|
||||
} else {
|
||||
g.SetHostname(stringid.TruncateID(b.ContainerID))
|
||||
hostname := stringid.TruncateID(b.ContainerID)
|
||||
defConfig, err := config.Default()
|
||||
if err != nil {
|
||||
return false, "", fmt.Errorf("failed to get container config: %w", err)
|
||||
}
|
||||
if defConfig.Containers.ContainerNameAsHostName {
|
||||
if mapped := mapContainerNameToHostname(b.Container); mapped != "" {
|
||||
hostname = mapped
|
||||
}
|
||||
}
|
||||
g.SetHostname(hostname)
|
||||
}
|
||||
} else {
|
||||
g.SetHostname("")
|
||||
|
||||
Reference in New Issue
Block a user