summaryrefslogtreecommitdiff
path: root/pkg/spec/spec.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/spec/spec.go')
-rw-r--r--pkg/spec/spec.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go
index d9888e999..97305610a 100644
--- a/pkg/spec/spec.go
+++ b/pkg/spec/spec.go
@@ -1,15 +1,16 @@
package createconfig
import (
+ "os"
"strings"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/docker/docker/daemon/caps"
"github.com/docker/docker/pkg/mount"
"github.com/docker/go-units"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/rootless"
"github.com/sirupsen/logrus"
)
@@ -73,6 +74,14 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint
g.AddAnnotation(key, val)
}
g.SetRootReadonly(config.ReadOnlyRootfs)
+ if config.Hostname == "" {
+ if config.NetMode.IsHost() {
+ config.Hostname, err = os.Hostname()
+ if err != nil {
+ return nil, errors.Wrap(err, "unable to retrieve hostname")
+ }
+ }
+ }
g.SetHostname(config.Hostname)
if config.Hostname != "" {
g.AddProcessEnv("HOSTNAME", config.Hostname)