Skip to content

Instantly share code, notes, and snippets.

@helayoty
Created January 4, 2026 23:36
Show Gist options
  • Select an option

  • Save helayoty/f7cc4f8ac857ef71250e5eaae6deb1e6 to your computer and use it in GitHub Desktop.

Select an option

Save helayoty/f7cc4f8ac857ef71250e5eaae6deb1e6 to your computer and use it in GitHub Desktop.
Cleanup container build by runc
#!/bin/bash
# ==============================================================================
# Cleanup script for runc container
# ==============================================================================
export CONTAINER_ID=container-1
echo "Cleaning up container: ${CONTAINER_ID}"
# Kill container
echo "Killing container..."
sudo runc kill ${CONTAINER_ID} TERM || echo "Container already stopped"
# Wait a moment for it to stop
sleep 2
# Delete container
echo "Deleting container..."
sudo runc delete ${CONTAINER_ID} || echo "Container already deleted"
# Clean up networking
echo "Cleaning up networking..."
sudo ip link delete veth0 2>/dev/null || echo "veth0 already deleted"
sudo rm -f /run/netns/${CONTAINER_ID} || echo "Network namespace link already removed"
# Remove bundle directory
echo "Removing bundle directory..."
rm -rf ~/${CONTAINER_ID}
echo "Cleanup complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment