Skip to content

Instantly share code, notes, and snippets.

@sethdmoore
Created April 19, 2016 01:17
Show Gist options
  • Save sethdmoore/bf4d6e332ec1418c567ddfc9294bd9c6 to your computer and use it in GitHub Desktop.
Save sethdmoore/bf4d6e332ec1418c567ddfc9294bd9c6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"gopkg.in/lxc/go-lxc.v2"
)
func main() {
lxcpath := lxc.DefaultConfigPath()
name := "foo"
c, err := lxc.NewContainer(name, lxcpath)
if err != nil {
fmt.Printf("Could not init container: %s\n", err.Error())
}
options := lxc.TemplateOptions{
Template: "/usr/share/lxc/templates/lxc-alpine",
}
if err := c.Create(options); err != nil {
fmt.Printf("Could not create container: %s\n", err.Error())
}
output, err := c.Execute("/bin/ls", "/")
// will always fail here with "container already defined"
if err != nil {
fmt.Printf("%s\n", err.Error())
} else {
fmt.Printf("%s\n", output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment