Cloud Native 5 min read

Common Kubernetes and Docker Commands

This article provides a concise reference of frequently used Kubernetes (kubectl) and Docker command‑line instructions, covering cluster inspection, pod and service queries, resource creation, deletion, as well as container inspection, logging, and interactive shell access.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Common Kubernetes and Docker Commands

Kubernetes (kubectl) Common Commands

View cluster information kubectl cluster-info View component statuses

kubectl -s http://localhost:8080 get componentstatuses

Show pods with node information kubectl get pods -o wide Display pod definitions in YAML kubectl get pods -o yaml List Replication Controllers kubectl get rc List services kubectl get service List nodes kubectl get nodes Find pods by selector kubectl get pod --selector name=redis Show environment variables of a running pod

kubectl exec <span style="color:#e6c07b;">pod-name</span> env

Create resources from a file kubectl create -f filename Replace resources (optional force) kubectl replace -f filename [--force] Delete resources

kubectl delete -f filename
kubectl delete pod pod-name
kubectl delete rc rc-name
kubectl delete service service-name
kubectl delete pod --all

Docker Container Common Commands

List running containers docker ps List all containers docker ps -a Show container IP docker exec ContainerID hostname -i View container logs (follow) docker logs -f ContainerID Enter a Linux container interactively

docker run -it imageID /bin/bash
docker run -i -t imageID /bin/bash

Attach to a running container

docker attach db3
docker attach d48b21a7e439

Note: db3 is the container name (NAMES) and d48b21a7e439 is the container ID (CONTAINER ID). Using docker exec -it ContainerID /bin/bash provides an interactive shell that remains active after exiting the command, unlike a simple docker attach which terminates the container when exit is issued.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLICloud NativeDockerOperationsKubernetesContainers
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.