Below are list of frequently used commands. This would come very handy while working with docker & kubernetes.
Thursday, 23 September 2021
Dockers and Kubernetes Cheat sheet
| Sl No. | Commands | Purpose |
|---|---|---|
| INFORMATION COMMANDS | ||
| 1 | docker --version | Docker Version |
| 2 | docker version | Docker Version Detailed |
| 3 | docker images | Docker image list |
| 4 | docker ps | Containers List (running) |
| 5 | docker ps -a | Containers List |
| 5 | docker system df | Summary of the System space used |
| 6 | docker logs [CONTAINER] | List the logs from a running container |
| 7 | docker port [CONTAINER] | Show port (or specific) mapping for a container |
| 8 | docker top [CONTAINER] | Show running processes in a container |
| CONTAINER COMMANDS | 9 | docker run [image:version] | Create container |
| 10 | docker create [IMAGE] | Create container (without starting it) |
| 11 | docker run --rm [IMAGE] | Create container & remove container after it exits |
| 12 | docker run -td [IMAGE] | Create container & keep it running |
| 13 | docker run -it [IMAGE] | Create container & allocates a pseudo-TTY connected to the container’s stdin, and creates an interactive bash shell in the container |
| 14 | docker run -it-rm [IMAGE] | Create container & runs a command inside the container. Once it executes the command, the container is removed |
| 15 | docker stop [containerName] | Stop Container |
| 15 | docker stop $(docker ps -q) | Stop all running Containers |
| 16 | docker start [CONTAINER] | Start Container |
| 17 | docker rm [CONTAINER] | Remove container (if not running) |
| 18 | docker builder prune --all | Remove all unused build cache |
| 19 | docker restart [CONTAINER] | Stop a running container and start it up again |
| 20 | docker pause [CONTAINER] | Pause processes in a running container |
| 21 | docker unpause [CONTAINER] | UnPause processes in a running container |
| 22 | docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME] | Rename existing container |
| 23 | docker wait [CONTAINER] | Block a container until others stop (after which it prints their exit codes) |
| 24 | docker kill [CONTAINER] | Kill a container by sending a SIGKILL to a running container |
| 25 | docker attach [CONTAINER] | Attach local standard input, output, and error streams to a running container |
| 26 | docker run [IMAGE] [COMMAND] | Run a command in a new container |
| 27 | docker rm -f ${docker ps -a -q} | Remove all running containers |
| 28 | docker attach [CONTAINER] | Attach local standard input, output, and error streams to a running container |
| 29 | docker exec -it [container] bash | Run a command in the running container |
| 30 | docker container cp [localfolder] [containerName:/tmp] | Copy files from local to container |
| 31 | docker container [containerName] [command] i.e commands like ls, tmp | Execute commands inside the container |
| 32 | docker container commit [containerName] shiv/newImgname:1.0 | Create new image from running container |
| 33 | docker container commit –change'CMD ["java","-jar","/tmp/testapp.jar"]' [containerName] shiv/newImgname:2.0 | Create new image from running container & make any app run when the image is started. |
| 33 | docker container prune | Remove all stopped containers |
| 34 | docker run -d -p 5000:5000 |
Run docker image in a detached mode with a new port |
| IMAGE COMMANDS | ||
| 35 | docker pull [IMAGE] | Pull Image from the registry |
| 36 | docker push [IMAGE] | Push Image to the registry |
| 37 | docker build -t sva01/apache:2.0 . | Build and tag image |
| 38 | docker build -f dockerfiles/Dofile.debug -t myapp_debug . | Build and tag image with the given file |
| 39 | docker commit [CONTAINER] [NEW_IMAGE_NAME] | Create an image from a container |
| 40 | docker rmi [IMAGE] | Remove an image |
| NETWORK COMMANDS | ||
| 41 | docker network ls | List Networks |
| 43 | docker network rm [NETWORK] | Remove one or more networks |
| 44 | docker network inspect [NETWORK] | Show information on one or more networks |
| 45 | docker network connect [NETWORK] [CONTAINER] | Connects a container to a network |
| 46 | docker network disconnect [NETWORK] [CONTAINER] | Disconnect a container from a network |
| DOCKER-COMPOSE COMMANDS | ||
| 47 | docker-compose -f [dockercomposeFile] up | Start containers with docker-compose file |
| 48 | docker-compose -f [dockercomposeFile] up -d | Start containers with docker-compose file & Run containers in the background |
| 49 | docker-compose -f [dockercomposeFile] down | Stops containers specified in docker-compose file |
| KUBERNETES COMMANDS | ||
| 50 | kubectl create -f |
To create service,deployment, Relication controller etc. |
| 51 | kubectl get pods | To the list of pods running in a kubernate cluster |
| 52 | kubectl get all | To list all pods, services, RCs etc |
| 53 | minikube dashboard | To view the kuberenetes dashboard if you have installed minikube |
| 54 | kubectl delete rc –all | To delete all Replication controllers |
| 55 | kubectl delete rc [rc name] | To delete specific Replication controller |
| 56 | kubectl get rc | To get the list of RCs |
| 57 | kubectl delete pods –all | To delete all pods |
| 58 | kubectl delete pod [podname] | To delete specific pod |
| 59 | kubectl delete deploy –all | To delete all deployments |
| 60 | kubectl logs [podname] | To get logs from specific pod |
| 61 | kubectl describe service | To get details about service |
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment