1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

dockerinit: set hostname

Set the hostname in dockerinit instead of with lxc utils.  libvirt-lxc
doesn't have a way to do this, so do it in a common place.
This commit is contained in:
Josh Poimboeuf 2013-10-29 13:31:00 -05:00
parent 8224e13bd2
commit f7c7f7978c
3 changed files with 22 additions and 9 deletions

View file

@ -26,6 +26,14 @@ type DockerInitArgs struct {
args []string
}
func setupHostname(args *DockerInitArgs) error {
hostname := getEnv(args, "HOSTNAME")
if hostname == "" {
return nil
}
return syscall.Sethostname([]byte(hostname))
}
// Setup networking
func setupNetworking(args *DockerInitArgs) error {
if args.gateway == "" {
@ -132,9 +140,23 @@ func setupEnv(args *DockerInitArgs) {
}
}
func getEnv(args *DockerInitArgs, key string) string {
for _, kv := range args.env {
parts := strings.SplitN(kv, "=", 2)
if parts[0] == key && len(parts) == 2 {
return parts[1]
}
}
return ""
}
func executeProgram(args *DockerInitArgs) error {
setupEnv(args)
if err := setupHostname(args); err != nil {
return err
}
if err := setupNetworking(args); err != nil {
return err
}