This document provides a side-by-side comparison of common commands for Docker and Kubernetes, two widely used containerization and orchestration platforms.
Building and Managing Containers:
Task | Docker Command | Kubernetes Command |
---|
Building an image | docker build -t <image-name> . | N/A (Kubernetes relies on Docker images) |
Pushing an image to a registry | docker push <image-name> | N/A (Handled by container registry, not Kubernetes) |
Pulling an image from a registry | docker pull <image-name> | kubectl apply -f <image-name> (using YAML) |
Listing images | docker images | N/A (Kubernetes doesn't manage local images) |
Removing an image | docker rmi <image-id> | N/A (Images are managed by Docker) |
Running and Managing Containers:
Task | Docker Command | Kubernetes Command |
---|
Running a container | docker run -d --name <name> <image> | kubectl run <name> --image=<image> |
Stopping a container | docker stop <container-id> | kubectl delete pod <name> (or scale down) |
Restarting a container | docker restart <container-id> | N/A (Recreate the pod with a new image version) |
Listing running containers | docker ps | kubectl get pods |
Inspecting a container | docker inspect <container-id> | N/A (Use kubectl describe pod <name> ) |
Executing a command in a container | docker exec -it <container-id> <command> | kubectl exec -it <pod-name> -- <command> |
Removing a container | docker rm <container-id> | kubectl delete pod <name> |
Viewing container logs | docker logs <container-id> | kubectl logs <pod-name> |
Networking and Services:
Task | Docker Command | Kubernetes Command |
---|
Exposing a port in a container | -p <host-port>:<container-port> | Defined in YAML or kubectl expose command |
Creating a network | docker network create <name> | N/A (Kubernetes manages networking) |
Creating a service (LoadBalancer) | N/A (Handled by orchestration) | kubectl expose deployment <name> --type=LoadBalancer --port=<port> |
Creating a service (NodePort) | N/A (Handled by orchestration) | kubectl expose deployment <name> --type=NodePort --port=<port> |
Creating a service (ClusterIP) | N/A (Handled by orchestration) | kubectl expose deployment <name> --type=ClusterIP --port=<port> |
Volumes and Storage:
Task | Docker Command | Kubernetes Command |
---|
Creating a volume | docker volume create <name> | kubectl apply -f <volume-definition.yaml> |
Attaching a volume to a container | docker run -v <volume-name>:/path ... | Defined in YAML or kubectl attach command |
Creating a persistent volume (PV) | N/A (Handled by Kubernetes) | kubectl apply -f <persistent-volume.yaml> |
Creating a persistent volume claim (PVC) | N/A (Handled by Kubernetes) | kubectl apply -f <persistent-volume-claim.yaml> |
Configuration and Secrets:
Task | Docker Command | Kubernetes Command |
---|
Setting environment variables | -e <key=value> | Defined in YAML or kubectl create configmap |
Creating a secret | docker secret create <name> <file> | kubectl create secret generic <name> --from-file=<path> |
Using environment variables from file | docker run --env-file=<file> ... | Defined in YAML or kubectl create secret generic |
Miscellaneous:
Task | Docker Command | Kubernetes Command |
---|
Creating a namespace | N/A (Handled by Kubernetes) | kubectl create namespace <name> |
Switching between contexts | docker context use <context> | kubectl config use-context <context> |
Scaling deployments | N/A (Handled by orchestration) | kubectl scale deployment <name> --replicas=<count> |
This comparison provides a quick reference for common commands used in Docker and Kubernetes. It's important to note that Docker focuses on containerization, while Kubernetes is an orchestration platform for managing containerized applications at scale. As a result, some tasks are handled differently or not applicable in one platform versus the other.
No comments:
Post a Comment