From f48cc7d7fedf647e0e9ffd23efb31deb342eac4a Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 26 Feb 2018 14:19:22 +0000 Subject: [PATCH] ctr: unpack the image on run if necessary Without this `ctr run` can fail with: ctr: parent snapshot sha256:70798fd80095f40b41baa5d107fb61532bfe494d96313fea01e8fcbf4e8743ee does not exist: not found My image was produced by buildkit, which doesn't unpack (I think this makes sense since buildkit doesn't know if I am going to run the image or export/push it etc). Signed-off-by: Ian Campbell --- cmd/ctr/commands/run/run_unix.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index 51ac4f7bb..15fad5b0a 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -68,14 +68,24 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli if context.Bool("rootfs") { opts = append(opts, oci.WithRootFSPath(ref)) } else { + snapshotter := context.String("snapshotter") image, err := client.GetImage(ctx, ref) if err != nil { return nil, err } + unpacked, err := image.IsUnpacked(ctx, snapshotter) + if err != nil { + return nil, err + } + if !unpacked { + if err := image.Unpack(ctx, snapshotter); err != nil { + return nil, err + } + } opts = append(opts, oci.WithImageConfig(image)) cOpts = append(cOpts, containerd.WithImage(image), - containerd.WithSnapshotter(context.String("snapshotter")), + containerd.WithSnapshotter(snapshotter), // Even when "readonly" is set, we don't use KindView snapshot here. (#1495) // We pass writable snapshot to the OCI runtime, and the runtime remounts it as read-only, // after creating some mount points on demand.