Reputation: 3995
Here's what I want to accomplish:
Run Docker and be able to manage its images/containers from containerd's API. This is purely an educational exercise.
What I've tried:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/dotnet/runtime latest ec54a6c985a0 11 days ago 186MB
$ nerdctl --address /var/run/docker/containerd/containerd.sock -n moby images
REPOSITORY TAG IMAGE ID CREATED SIZE
package main
import (
"context"
"log"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
)
func main() {
if err := test(); err != nil {
log.Fatal(err)
}
}
func test() error {
client, err := containerd.New("/var/run/docker/containerd/containerd.sock")
if err != nil {
return err
}
defer client.Close()
ctx := namespaces.WithNamespace(context.Background(), "moby")
images, err := client.ListImages(ctx)
if err != nil {
return err
}
log.Printf("%v images\n", len(images))
return nil
}
The fact that I'm getting successful connections indicates things are on the right track. I just don't understand why it's not seeing the same results between Docker commands and the calls directly into containerd.
Upvotes: 0
Views: 638
Reputation: 3995
Got an answer from Docker maintainer Sebastiaan van Stijn:
dockerd uses the runtime components of containerd, but not (yet?) the image store and snapshotters, which is why you don't see the images, only containers
Upvotes: 0