-
-
Save vmarmol/2a8eb8bbbdee4a2b9400 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 | |
} | |
// 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