Skip to content

Instantly share code, notes, and snippets.

@vmarmol
Forked from crosbymichael/api.go
Created July 17, 2014 18:05
Show Gist options
  • Save vmarmol/f5b98bb0f191e0784d59 to your computer and use it in GitHub Desktop.
Save vmarmol/f5b98bb0f191e0784d59 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
}
factory, err := libcontainer.New(config)
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