Skip to main content

Docker wrapper for containerd and common commands


Why

As Kubernetes slowly moves away from Docker, it is important to know a few ctr and crictl commands in order to troubleshoot problems. I have used Docker for over 6 years in production and don't usually need to look up commands like stats, load, save, ps etc.

However, without the familiar Docker command line it can be hard to perform these tasks, especially when under pressure debugging a production issue.

So I wrote the following shell script hack below. As containerd is name spaced, some commands need to include the namespace k8s.io to provide a useful response. Containerd also knows the concept of pods, so the pause containers are not visible for certain commands.

#!/bin/bash

ARG=$1
MSG="##### No docker installed, running this for you instead:"

case $ARG in

info)
  echo "$MSG ctr version"
  ctr version
  ;;

ps)
  echo "$MSG ctr -n k8s.io containers list - or crictl pods"
  crictl pods
  ;;

rm)
  echo "$MSG ctr -n k8s.io containers rm $2"
  ctr -n k8s.io containers rm $2
  ;;

pods)
  echo "$MSG crictl pods"
  crictl pods
  ;;

images)
  echo "$MSG crictl images"
  crictl images
  ;;

inspect)
  echo "$MSG ctr -n k8s.io container info $2"
  ctr -n k8s.io container info $2
  ;;

load)
  echo "$MSG ctr -n k8s.io image import $2"
  ctr -n k8s.io image import $2
  ;;

save)
  echo "$MSG ctr -n k8s.io image export $2"
  ctr -n k8s.io image export $2
  ;;

pull)
  echo "$MSG crictl pull $2"
  crictl pull $2
  ;;

*)
  echo "$MSG sorry, command $ARG unknown"
  ;;

esac

Links

https://kubernetes.io/docs/tasks/debug-application-cluster/crictl/


Comments