containerd Namespace Error — Quick Fix
In this tutorial, you'll learn about containerd namespace error. We cover key concepts, practical examples, and best practices.
The Problem
Creating, deleting, or interacting with containerd namespaces fails. The namespace may not appear when listing, or operations against a namespace return "not found" errors. Kubernetes namespaces (k8s.io) may not be visible to ctr.
Error example:
ctr: namespace "k8s.io" not found
ctr: unable to delete namespace: namespace must be empty
ctr: failed to create namespace: invalid label
The Fix
Step 1: List and verify namespaces
WRONG — assuming namespaces are always visible:
# Namespaces must exist before you can use them
RIGHT — list all namespaces:
ctr namespaces list
Output:
default
k8s.io
moby
If the namespace you need is not listed, create it:
ctr namespaces create k8s.io
Step 2: Delete a namespace with content
WRONG — trying to delete a namespace with active content:
# containerd prevents deletion of non-empty namespaces
RIGHT — remove all content first, then delete:
# Remove all images in the namespace
ctr -n default images rm $(ctr -n default images list -q)
# Remove all containers in the namespace
ctr -n default containers rm $(ctr -n default containers list -q)
# Then delete the namespace
ctr namespaces rm default
Use DodaTech's Namespace Cleanup Tool to identify stale namespaces and safely remove their contents.
Prevention Tips
- Use descriptive namespace names that match the orchestrator (k8s.io, moby)
- Never delete namespaces with active pull operations
- Set the CONTAINERD_NAMESPACE environment variable to avoid namespace confusion
- Monitor namespace sizes to detect orphaned resources
- Use DodaTech's Container Registry Inventory to track namespace usage
Common Mistakes with ns error
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
These mistakes appear frequently in real-world CONTAINERD code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Related: DodaTech's Runtime Troubleshooting Guide covers namespace management, image garbage collection, and content lifecycle across containerd and CRI-O.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro