Docker commands cheatsheet
In this blog we will see the most essential docker commands and the some of the extra docker commands you ever need
General Docker Commands-
Docker Commands | use case |
docker -d | Start the docker daemon |
docker info | Display system-wide information |
Docker commands for Images-
Docker commands | use case |
docker build -t <image-name> . | Build a image with Dockerfile |
docker build -t <image-name> . -no-cache | Build a image with Dockerfile with no cache |
docker images | list the images on the machine |
docker rmi <image-name> | Delete an image |
docker image prune | remove all unused images |
docker image prune -all | remove all unused images as well as images which are not attached to a container |
docker image save <image-name> -o <filename>.tar | save the image in the machine in .tar format |
docker image load -i <filename>.tar | load the image from .tar file |
docker image history <image-name> | Gets you the layers of the image |
Docker Commands for Docker Hub-
Docker Commands | use case |
docker login -u <username> | login into DockerHub |
docker pull <image-name>:<image-tag> | Pulling a docker image from DockerHub |
docker push <repository>/<image-name>:<image-tag> | Pushing the image to Dockerhub |
docker search <image-name> | Search for image on Hub |
Docker Commands for Docker Container -
Docker Commands | use case |
docker run --name <container-name> <image-name> | Create and run the container with name |
docker run -p <host-port>:<containerport> <image-name> | Run a container with and publish a container’s port to the host |
docker run -d <image-name> | Runs a container in detached mode |
docker start <container-name> | start a existing container |
docker stop <container-name> | stop a running container |
docker rm <container-name> | removes a stopped container |
docker ps | list all the running containers |
docker ps -a | list all the running containers as well as stopped containers |
docker exec -it <container-name> sh | open's shell inside the container |
docker logs -f <container-name> | fetch and follows the logs of the container |
docker container stats | View resource usage stats |
Some Advanced Commands -
Docker Commands | Use case |
| used to setup context for local machine or remote machine |
| used to copy file from host machine to existing container |
| shows all the disk usage of the container,images,local volume |
| removes all unused data using disk space |
Thanks for reading <3
Subscribe to my newsletter
Read articles from Abhijeet directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Abhijeet
Abhijeet
I am Abhijeet, a Computer Science Master's Degree holder. with an A+ grade, specializing in AWS, Azure, Docker, Kubernetes, Terraform, and DevOps tools.