lxc / go-lxc

Go bindings for liblxc
https://linuxcontainers.org/lxc
Other
430 stars 76 forks source link

ERROR: Creating container faled + other error #125

Closed sometimescool22 closed 5 years ago

sometimescool22 commented 5 years ago

Container noob here. Trying to run a modified version of the Create example. Here's my code:

func main() {
    verbose := true
    c, err := lxc.NewContainer("gotest", "/var/snap/lxd/common/lxd/unix.socket")
    if err != nil {
        log.Fatalf("ERROR: %s\n", err.Error())
    }
    defer c.Release()

    log.Printf("Creating container...\n")
    if verbose {
        c.SetVerbosity(lxc.Verbose)
    }

    options := lxc.TemplateOptions{
        Template:             "download",
        Distro:               "ubuntu",
        Release:              "trusty",
        Arch:                 "amd64",
        FlushCache:           false,
        DisableGPGValidation: false,
    }

    if err := c.Create(options); err != nil {
        log.Printf("ERROR: %s\n", err.Error())
    }
}

But I'm getting ERROR: creating the container failed. I'm on Pop OS (based on Ubuntu 19.04) and have installed lxd with apt follow this. I'm able to start a container with lxc start ubuntu.

Also, the Console example fails with ERROR: container is not running: "test". I've verified with lxc list that test is running.

Any help would be great, thanks.

stgraber commented 5 years ago

go-lxc drives liblxc which is the low level C container runtime, it does not interact with LXD which is one level up from go-lxc.

It sounds like you want to create and interact with LXD containers, to do so, you want to use the LXD REST API and its own Go module at https://godoc.org/github.com/lxc/lxd/client

sometimescool22 commented 5 years ago

Ah, ok. Thanks.