From cd7102a70e7f3555df832c4c1bcf958e121cbf4d Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 14 Aug 2018 14:59:24 -0400 Subject: Fix handling of hostname in --net=host Hostname should be set to the hosts hostname when network is none. Signed-off-by: Daniel J Walsh Closes: #1274 Approved by: giuseppe --- pkg/spec/spec.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pkg') diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go index d9888e999..bceae4677 100644 --- a/pkg/spec/spec.go +++ b/pkg/spec/spec.go @@ -1,6 +1,7 @@ package createconfig import ( + "os" "strings" "github.com/docker/docker/daemon/caps" @@ -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) -- cgit v1.2.3-54-g00ecf