Last active
August 29, 2015 14:04
-
-
Save crosbymichael/b32e1c7f6e67d38bcb41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"libcontainer" | |
"os" | |
) | |
func startContainer() error { | |
config, err := loadConfigFromSomewhere() | |
if err != nil { | |
return err | |
} | |
factory, err := libcontainer.New("/var/lib/docker/execdrivers/libcontainer") | |
if err != nil { | |
return err | |
} | |
process := &libcontainer.Process{ | |
Stdin: os.Stdin, | |
Stdout: os.Stdout, | |
Stderr: os.Stderr, | |
Args: []string{ | |
"/bin/bash", | |
}, | |
Env: []string{ | |
"TERM=xterm", | |
}, | |
} | |
container, err := factory.Create("container-1", process) | |
if err != nil { | |
return err | |
} | |
defer container.Destroy() | |
// container is now running | |
pids, err := container.Processes() | |
if err != nil { | |
return err | |
} | |
// run another bash shell | |
pid, exitCode, err := container.Start(process) | |
if err != nil { | |
return err | |
} | |
go func() { | |
bashExitCode := <-exitCode | |
log.Printf("bash exited with %d", bashExitCode) | |
}() | |
// freeze everything | |
if err := container.Pause(); err != nil { | |
return err | |
} | |
// resume | |
if err := container.Resume(); err != nil { | |
return err | |
} | |
stats, err := container.Stats() | |
if err != nil { | |
return err | |
} | |
if err := container.StartFunc(func() error { | |
return syscall.Mknod(...) | |
}); err != nil { | |
return err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment