What is the path to the containerd socket in the host? #1417
-
| I am trying to connect to  Code func main() {
	client, err := containerd.New("/run/containerd/containerd.sock")
	if err != nil {
		panic(err)
	}
	defer client.Close()
} | 
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
| If you are running rootless containerd, the .sock is in a different  | 
Beta Was this translation helpful? Give feedback.
-
| I was wondering how you did this for rootless containerd, so adopted the example from https://containerd.io/docs/getting-started/ package main
import (
	"context"
	"fmt"
	"log"
	//"github.com/containerd/containerd"
	"github.com/containerd/nerdctl/pkg/clientutil"
	"github.com/containerd/nerdctl/pkg/rootlessutil"
)
func main() {
	if err := example(); err != nil {
		log.Fatal(err)
	}
}
func example() error {
	if rootlessutil.IsRootlessParent() {
		return rootlessutil.ParentMain()
	}
	//client, err := containerd.New("/run/containerd/containerd.sock")
	client, ctx, _, err := clientutil.NewClient(context.Background(), "default", "/run/containerd/containerd.sock
")
	if err != nil {
		return err
	}
	defer client.Close()
	version, err := client.Version(ctx)
	if err != nil {
		return err
	}
	fmt.Printf("containerd version: %s\n", version.Version)
	fmt.Printf("containerd address: %s\n", client.Conn().Target())
	fmt.Printf("rootless: %v\n", rootlessutil.IsRootless())
	return nil
}It will actually print the same address for both (unlike Docker or Podman sockets), since it is in a "rootlesskit" Linux namespace. | 
Beta Was this translation helpful? Give feedback.
-
| The socket path is  | 
Beta Was this translation helpful? Give feedback.
The socket path is
/proc/$(cat $XDG_RUNTIME_DIR/containerd-rootless/child_pid)/root/run/containerd/containerd.sockin the guest, but it is not exposed to the host, as most containerd operations needs the daemon and the client to share the same filesystem