Skip to content

Instantly share code, notes, and snippets.

@ijc
Created June 13, 2017 11:18
Show Gist options
  • Save ijc/ee11fd5a90f5c27005bfcec63dbac4f5 to your computer and use it in GitHub Desktop.
Save ijc/ee11fd5a90f5c27005bfcec63dbac4f5 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
)
func main() {
sock := "/run/containerd/containerd.sock"
client, err := containerd.New(sock)
if err != nil {
log.Fatalf("creating containerd client")
}
ctx := namespaces.WithNamespace(context.Background(), "default")
image, err := client.Pull(ctx, "docker.io/library/nginx:alpine", containerd.WithPullUnpack)
if err != nil {
log.Fatalf("pulling container image: %s", err)
}
spec, err := containerd.GenerateSpec(containerd.WithImageConfig(ctx, image))
if err != nil {
log.Fatalf("spec: %s\n", err)
}
_, err = client.NewContainer(ctx, "issue981", containerd.WithSpec(spec))
if err != nil {
log.Fatalf("container: %s\n", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment