Day-20: Docker Commands Cheat-sheet

Hey there! I am Deepak!! Passionate About Cloud & AWS☁️| DevOps ♾️ Technologies 👩🏻💻 And Skilled with Git 🔀 | Docker 🐳 | Kubernetes ☸ | Jenkins 🛠️
👏 Welcome to my blog!!
Now it's time to take your Docker skills to the next level by creating a comprehensive cheat-sheet of all the commands you've learned so far. This cheat-sheet should include commands for Docker, Dockerfile, Docker-Compose, Docker Volume as well as brief explanations of their usage. This cheat-sheet will not only help you in the future but also contribute to the DevOps community by providing a useful resource for others.😊🙌
Basic Commands
sudo apt install docker.io: To install dockerdocker -v / --version: Shows the installed docker versionsystemctl start docker / service docker start: Start docker servicesystemctl stop docker / service docker stop: Stop the docker servicesystemctl status docker / service docker status: Check the docker service statusdocker ps: Lists only running containersdocker ps -a: Shows all containers including created, running, and exited.docker images -a: Lists all images createddocker logs: Shows the logs of the containerdocker inspect [container-name/image/volume]: View detail information about an image, container, volumedocker stats: View resource usage statistics for one or more containersdocker port: List the port mappings for a containerdocker top: To view the processes inside a container
Manage images and containers - Commands
docker pull [username/repository:tag]: Download images from registry ordocker pull [image-name]docker build -t [tagname/new-image-name] [directory/]: Build a new docker image from Docker filedocker run [image]: Starts a new container from an imagedocker run --name [container] [image]: Start new container and assign a name of containerdocker run -d [image]: Starts a new container in backenddocker run -p [Hostport]:[container-port] [image]: Start new container with map ports to containerdocker run -it [image]: Start new container in interactive mode(Login to the container)with the image through command linedocker run -e [myvar=myprop] [image]: Specify an environmental variable for a docker containerdocker exec -it [container-ID/name] [executable]: Start a shell or entering inside a running container or log in to the running containerdocker rename [oldname] [newname]: Rename the containerdocker save [image] > [archivefile]ordocker save -o [archivefile] [image]: Save an image to a tar archivedocker commit [container-name] [imagename]: Create an image of docker containerdocker load -i [archivefile]: Load an image to a tar archivedocker kill [container]: Forced shutdown of running containerdocker rm [container-name/id]: Delete the stop containerdocker rm -f [container-name/id]: Delete the running containerdocker rm $(docker ps -a -q): Delete all running containerdocker rmi [image]: Delete a docker imagedocker rmi $(docker images -q): Delete all docker imagesdocker system prune: Delete all dangling containers, unused images and containersdocker login: Login cli session with registry like Dockerhub using credentialsIt will ask to enter the username and password
docker remote -v: Lists out remote docker hostdocker tag [image] [registry-username/repository:tag]: Set the tag for images pushed to Dockerhubdocker push [registry-username/repository:tag]: Upload images to registry
Docker-Compose & Volumes -Commands
docker-compose config: Validate the docker-compose filedocker-compose up -d: Start multiple containers at once in background from the docker-compose filedocker-compose ps: Lists running containre created from docker-compose filedocker-compose ps -a: Lists all running and stoped containre created from docker-compose filedocker-compose down: Stop all running containers and also remove themdocker compose logs: Shows the logs of running containers with docker composedocker compose -d --scale up [service]=[no. of times]: Scale up the services or containers with limited times as prescribed in yaml filedocker service [service] --replicas [no. of times] [image]: Autoscaling services with set number of timesdocker volume ls: Lists all volumesdocker volume create [volume]: Create a volume in the machinedocker run -v [HostDir:TargetDir] -it [container] [image]: Create and connect a container to a volume or mapping local directory with a docker containerdocker volume rm [volume]: Delete unused volume from machinedocker volume prune: Delete all the available docker volumesdocker volume inspect [volume-name]: Inspects the volume (Detailed information about volume)
Thank you for reading the article.
Thanks for your valuable time.
Happy Learning !... Keep Learning ! 😊



