Unable to retrieve data from Docker-managed containerd by using containerd-based CLI directly

586 views Asked by At

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:

  1. Started dockerd
  2. 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
  1. Installed nerdctl to use as a CLI for containerd.
  2. 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
  1. 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.

1

There are 1 answers

0
Matt Thalman On BEST ANSWER

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