summaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r--libpod/container_internal_linux.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 38dfa7ab7..8ee0fb456 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -385,6 +385,16 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
}
}
+
+ for _, i := range c.config.Spec.Linux.Namespaces {
+ if i.Type == spec.UTSNamespace {
+ hostname := c.Hostname()
+ g.SetHostname(hostname)
+ g.AddProcessEnv("HOSTNAME", hostname)
+ break
+ }
+ }
+
if c.config.UTSNsCtr != "" {
if err := c.addNamespaceContainer(&g, UTSNS, c.config.UTSNsCtr, spec.UTSNamespace); err != nil {
return nil, err
@@ -418,15 +428,6 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
}
- for _, i := range c.config.Spec.Linux.Namespaces {
- if i.Type == spec.UTSNamespace {
- hostname := c.Hostname()
- g.SetHostname(hostname)
- g.AddProcessEnv("HOSTNAME", hostname)
- break
- }
- }
-
// Only add container environment variable if not already present
foundContainerEnv := false
for _, env := range g.Config.Process.Env {
@@ -583,6 +584,12 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
return errors.Wrapf(err, "error retrieving dependency %s of container %s from state", ctr, c.ID())
}
+ if specNS == spec.UTSNamespace {
+ hostname := nsCtr.Hostname()
+ g.SetHostname(hostname)
+ g.AddProcessEnv("HOSTNAME", hostname)
+ }
+
// TODO need unlocked version of this for use in pods
nsPath, err := nsCtr.NamespacePath(ns)
if err != nil {