Container Management Cheat Sheet: Docker, Kubernetes, and Beyond

Introduction

Container management involves deploying, scaling, and operating application containers across clusters of hosts. Containers package applications with their dependencies, ensuring consistent operation across environments. Modern container management systems handle orchestration, networking, storage, and security, making applications more portable, scalable, and resilient.

Core Container Concepts

ConceptDescription
ContainerLightweight, standalone executable package including everything needed to run an application
ImageRead-only template with instructions for creating a container
RegistryRepository for storing and distributing container images
PodSmallest deployable unit in Kubernetes, containing one or more containers
NamespaceMechanism for isolating groups of resources within a cluster
OrchestrationAutomating deployment, scaling, and management of containerized applications

Docker Fundamentals

Essential Docker Commands

# Image Management
docker pull <image>           # Download an image from registry
docker build -t <name> .      # Build image from Dockerfile
docker images                 # List all images
docker rmi <image>            # Remove an image

# Container Lifecycle
docker run -d -p 8080:80 <image>  # Run container in background, map ports
docker ps                      # List running containers
docker ps -a                   # List all containers
docker stop <container>        # Stop a container
docker start <container>       # Start a stopped container
docker restart <container>     # Restart a container
docker rm <container>          # Remove a container

# Container Interaction
docker logs <container>        # View container logs
docker exec -it <container> sh # Interactive shell into container
docker cp <container>:/path ./local  # Copy files from container

Dockerfile Essentials

FROM node:14                           # Base image
WORKDIR /app                           # Set working directory
COPY package*.json ./                  # Copy files
RUN npm install                        # Run commands
EXPOSE 3000                            # Document port
CMD ["npm", "start"]                   # Default command

Kubernetes Fundamentals

Basic Kubernetes Architecture

  • Control Plane: API Server, Controller Manager, Scheduler, etcd
  • Nodes: kubelet, kube-proxy, Container Runtime

Essential Kubernetes Commands

# Cluster Information
kubectl cluster-info             # Display cluster info
kubectl get nodes                # List all nodes

# Workload Management
kubectl create -f file.yaml      # Create resource from file
kubectl apply -f file.yaml       # Apply changes to resource
kubectl get pods                 # List all pods
kubectl get deployments          # List all deployments
kubectl get services             # List all services
kubectl describe pod <name>      # Show detailed pod info
kubectl logs <pod>               # View pod logs
kubectl exec -it <pod> -- sh     # Shell into pod
kubectl delete pod <name>        # Delete a pod

# Scaling and Updates
kubectl scale deployment/<name> --replicas=3  # Scale deployment
kubectl rollout status deployment/<name>      # Check rollout status
kubectl rollout undo deployment/<name>        # Rollback deployment

Key Kubernetes Resource Types

ResourcePurpose
PodBasic execution unit of applications
DeploymentManages ReplicaSets and provides declarative updates to Pods
ServiceExposes an application running on a set of Pods
ConfigMapStores non-confidential configuration data
SecretStores sensitive information like passwords
IngressManages external access to services
PersistentVolumeStorage resource provisioned by an administrator
StatefulSetManages stateful applications
DaemonSetEnsures all nodes run a copy of a Pod

Container Networking

Docker Network Types

  • Bridge: Default network for containers on a host
  • Host: Removes network isolation between container and host
  • Overlay: Connects multiple Docker daemons
  • Macvlan: Assigns MAC address to container
  • None: Disables networking

Kubernetes Networking Concepts

  • Cluster Network: Communication between pods across nodes
  • Service Discovery: Automatic detection of service endpoints
  • Network Policies: Rules controlling traffic between pods
  • Load Balancing: Distribution of traffic across pods

Container Storage

Docker Storage Options

  • Volumes: Preferred mechanism for persisting data
  • Bind Mounts: Map host directory to container
  • tmpfs Mounts: Store data in memory

Kubernetes Storage

  • Volumes: Pod-level storage
  • PersistentVolumes: Cluster-level storage resource
  • StorageClasses: Automate storage provisioning
  • VolumeSnapshots: Create backups of volumes

Container Security Best Practices

  • Use minimal base images (e.g., Alpine)
  • Run containers with least privileges
  • Scan images for vulnerabilities
  • Implement network segmentation
  • Use read-only filesystems where possible
  • Apply resource quotas
  • Never store secrets in container images
  • Enable content trust for image verification
  • Implement runtime security monitoring

Container Orchestration Comparison

FeatureDocker SwarmKubernetesAmazon ECS
ComplexityLowHighMedium
ScalabilityLimitedExtensiveGood
Auto-scalingLimitedAdvancedYes
Self-healingBasicAdvancedYes
Load BalancingBasicAdvancedYes
Rolling UpdatesYesAdvancedYes
CommunityModerateExtensiveAmazon-focused
Learning CurveGentleSteepModerate

Common Challenges and Solutions

ChallengeSolution
Container SprawlImplement lifecycle policies and garbage collection
Resource OverallocationSet resource limits and requests
Networking IssuesUse CNI plugins for advanced networking
Persistent StorageImplement appropriate volume solutions
Security ConcernsApply security context, network policies, and image scanning
Configuration ManagementUse ConfigMaps, Secrets, and Helm charts
Monitoring ComplexityImplement Prometheus/Grafana stack
Kubernetes ComplexityConsider managed services or simpler alternatives

Container Observability

Monitoring Solutions

  • Prometheus: Metrics collection and alerting
  • Grafana: Dashboards and visualization
  • cAdvisor: Container-level metrics
  • Datadog: Commercial monitoring solution
  • New Relic: Application performance monitoring

Key Metrics to Monitor

  • CPU and memory usage
  • Network I/O
  • Disk I/O
  • Request latency
  • Error rates
  • Container startup time
  • Restarts count

Production Best Practices

  • Use orchestration for production deployments
  • Implement CI/CD pipelines for container builds
  • Store images in private registries
  • Version images properly (avoid “latest” tag)
  • Health checks for all containers
  • Implement proper logging strategies
  • Use namespaces for resource isolation
  • Apply resource quotas and limits
  • Implement horizontal pod autoscaling
  • Use init containers for startup dependencies
  • Leverage operators for complex applications

Resources for Further Learning

Documentation

Books

  • “Docker in Action” by Jeff Nickoloff
  • “Kubernetes Up & Running” by Kelsey Hightower
  • “Container Security” by Liz Rice
  • “Kubernetes Patterns” by Bilgin Ibryam

Online Courses

  • Kubernetes Certified Administrator (CKA)
  • Docker Certified Associate (DCA)
  • RedHat OpenShift Administration

Community Resources

  • Kubernetes Slack
  • CNCF Landscape
  • DockerCon conferences
  • KubeCon conferences

Container Management Tools Ecosystem

  • Helm: Package manager for Kubernetes
  • Istio: Service mesh for Kubernetes
  • Podman: Docker alternative with daemonless architecture
  • Skaffold: Local Kubernetes development
  • Lens: Kubernetes IDE
  • Portainer: Container management UI
  • Rancher: Complete container management platform
  • OpenShift: Enterprise Kubernetes platform
  • k9s: Terminal UI for Kubernetes
  • Argo CD: GitOps continuous delivery tool
Scroll to Top