Skip to content
Go back

Docker, Kubernetes, and OpenShift Cheat sheets

Published:

Cheat Sheet: Introduction to Containers with Docker, Kubernetes, and OpenShift


CommandExplanationShorthand
docker image lsLists all imagesdocker images
docker image rm <image>Removes an imagedocker rmi
docker image pull <image>Pulls image from a Docker registrydocker pull
docker container ls -aLists all containersdocker ps -a
docker container run <image>Runs a container from an imagedocker run
docker container rm <container>Removes a containerdocker rm
docker container stop <container>Stops a containerdocker stop
docker container exec <container>Executes a command inside the containerdocker exec

I. Docker CLI & Environment Setup

CommandDescription
curl localhostPings the application running locally.
docker build <path>Builds a Docker image from a specified Dockerfile in the given path.
docker build . -t <tag>Builds a Docker image from the current directory (.) and tags it with a specified name and version (-t).
docker CLIRefers to the Docker Command Line Interface.
docker container rm <name/id>Removes one or more Docker containers.
docker imagesDisplays a list of all available Docker images on your local machine.
docker psLists currently running Docker containers.
docker ps -aLists all Docker containers, including those that have exited.
docker pull <image>Pulls the latest image or a specific repository from a registry (e.g., Docker Hub).
docker push <image>Pushes an image or a repository to a registry.
docker run <image>Runs a command in a new container created from a specified image.
docker run -p <local_port>:<container_port>Runs the container while publishing (mapping) its ports to the host machine.
docker stop <name/id>Stops one or more running containers gracefully.
docker stop $(docker ps -q)Stops all currently running containers by getting their IDs (-q).
docker tag <source_image> <target_image>Creates a new tag for a target image that refers to a source image.
docker --versionDisplays the version of the Docker CLI.
exitCloses the current terminal session.
export MY_NAMESPACE=<value>Exports a namespace as an environment variable, making it accessible in the current shell.
git clone <repo_url>Clones a Git repository that contains the artifacts needed for a project.
ibmcloud cr imagesLists images in the IBM Cloud Container Registry.
ibmcloud cr loginLogs your local Docker daemon into IBM Cloud Container Registry.
ibmcloud cr namespacesDisplays the namespaces available to the current user in the IBM Cloud Container Registry.
ibmcloud cr region-set <region>Ensures that you are targeting the region appropriate to your cloud account in IBM Cloud Container Registry.
ibmcloud targetProvides information about the IBM Cloud account you’re currently targeting.
ibmcloud versionDisplays the current version of the IBM Cloud CLI.
lsLists the files and directories in the current directory.

II. Understanding Kubernetes Architecture

CommandDescription
for ... do ... doneRuns a sequence of commands multiple times as specified in a loop.
kubectl apply -f <file.yaml>Applies a specified configuration to a resource, creating or updating it based on a YAML file.
kubectl config get-clustersDisplays all Kubernetes clusters defined in your kubeconfig file.
kubectl config get-contextsDisplays the current context (cluster, user, namespace) kubectl is using.
kubectl create <resource_type>Creates a new Kubernetes resource based on a given specification or type.
kubectl delete <resource_type> <name>Deletes specified Kubernetes resources.
kubectl describe <resource_type> <name>Provides detailed information about a specific resource or group of resources.
kubectl expose <resource_type>/<name>Exposes a resource (like a Deployment) to the internet as a Kubernetes service.
kubectl get <resource_type>Displays one or more resources.
kubectl get podsLists all the Pods in the current namespace.
kubectl get pods -o wideLists all the Pods with additional details like Node IP and internal IP.
kubectl get deploymentsDisplays all Deployments created in the current namespace.
kubectl get servicesLists all the Services created in the current namespace.
kubectl proxyCreates a proxy server between your localhost and the Kubernetes API server for easy access to cluster services.
kubectl run <name> --image=<image>Creates and runs a particular image in a Pod.
kubectl versionPrints the client (your local kubectl) and server (Kubernetes API) version information.

III. Managing Applications with Kubernetes

CommandDescription
kubectl autoscale deployment <name>Autoscales a Kubernetes Deployment by creating a Horizontal Pod Autoscaler (HPA) resource.
kubectl create configmap <name>Creates a ConfigMap resource.
kubectl get deployments -o wideLists deployments with comprehensive details (e.g., image used, selector).
kubectl get hpaLists Horizontal Pod Autoscalers (HPA) in the current namespace.
kubectl scale deployment <name> --replicas=<num>Scales a Deployment to a specified number of Pod replicas.
kubectl set image deployment/<name> <container>=<image>Updates the image used by a container within a Deployment, triggering a rolling update.
kubectl rollout <subcommand>Manages the rollout of a resource (e.g., status, history, undo).
kubectl rollout restart deployment <name>Restarts all Pods in a Deployment, useful for picking up config changes.
kubectl rollout undo deployment <name>Rolls back a Deployment to a previous revision.

IV. OpenShift CLI (oc)

CommandDescription
oc get <resource>Displays a specified OpenShift resource.
oc project <name>Switches to a different OpenShift project (namespace).
oc versionDisplays version information for the OpenShift CLI.

Comprehensive Glossary: Introduction to Containers with Docker, Kubernetes, and OpenShift

This comprehensive glossary includes terms from the course “Introduction to Containers with Docker, Kubernetes, and OpenShift,” as well as additional industry-recognized terms important for working in the field.


Container Basics


Kubernetes Basics


Managing Applications with Kubernetes


OpenShift Basics


Suggest Changes

Previous Post
Terraform - Create and SSH into an AWS EC2 Instance Using Terraform (Free Tier Guide for Beginners)
Next Post
Kubernetes Basics