Skip to content

Instantly share code, notes, and snippets.

@vmarmol
Forked from crosbymichael/api.go
Last active August 29, 2015 14:04
Show Gist options
  • Save vmarmol/2a8eb8bbbdee4a2b9400 to your computer and use it in GitHub Desktop.
Save vmarmol/2a8eb8bbbdee4a2b9400 to your computer and use it in GitHub Desktop.
package main
import (
"libcontainer"
"os"
)
func startContainer() error {
config, err := loadConfigFromSomewhere()
if err != nil {
return err
}
// Create the factory.
factory, err := libcontainer.New()
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",
},
}
// Create the container.
container, err := factory.Create(config, 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
if err := container.Exec(process); err != nil {
return err
}
// 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.ExecFunc(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