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:
- Started dockerd
- Verified I have a working daemon:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mcr.microsoft.com/dotnet/runtime latest ec54a6c985a0 11 days ago 186MB
- Installed nerdctl to use as a CLI for containerd.
- Attempted to connect to the same socket and namespace for containerd that Docker manages but getting no results:
$ nerdctl --address /var/run/docker/containerd/containerd.sock -n moby images
REPOSITORY TAG IMAGE ID CREATED SIZE
- I've also tried doing this directly from Go but still not getting any results:
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.
Got an answer from Docker maintainer Sebastiaan van Stijn: