[ctr] add HOSTNAME env for host network
Set the hostname environment var when using host networking via ctr Signed-off-by: Michael Crosby <michael@thepasture.io>
This commit is contained in:
parent
fda782a7b9
commit
6f60b3016f
@ -21,6 +21,7 @@ package run
|
||||
import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -200,7 +201,16 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
opts = append(opts, oci.WithPrivileged, oci.WithAllDevicesAllowed, oci.WithHostDevices)
|
||||
}
|
||||
if context.Bool("net-host") {
|
||||
opts = append(opts, oci.WithHostNamespace(specs.NetworkNamespace), oci.WithHostHostsFile, oci.WithHostResolvconf)
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get hostname")
|
||||
}
|
||||
opts = append(opts,
|
||||
oci.WithHostNamespace(specs.NetworkNamespace),
|
||||
oci.WithHostHostsFile,
|
||||
oci.WithHostResolvconf,
|
||||
oci.WithEnv([]string{fmt.Sprintf("HOSTNAME=%s", hostname)}),
|
||||
)
|
||||
}
|
||||
|
||||
seccompProfile := context.String("seccomp-profile")
|
||||
|
Loading…
Reference in New Issue
Block a user