Docker commands cheatsheet

AbhijeetAbhijeet
3 min read

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 Commandsuse case
docker -dStart the docker daemon
docker infoDisplay system-wide information

Docker commands for Images-

Docker commandsuse case
docker build -t <image-name> .Build a image with Dockerfile
docker build -t <image-name> . -no-cacheBuild a image with Dockerfile with no cache
docker imageslist the images on the machine
docker rmi <image-name>Delete an image
docker image pruneremove all unused images
docker image prune -allremove all unused images as well as images which are not attached to a container
docker image save <image-name> -o <filename>.tarsave the image in the machine in .tar format
docker image load -i <filename>.tarload the image from .tar file
docker image history <image-name>Gets you the layers of the image

Docker Commands for Docker Hub-

Docker Commandsuse 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 Commandsuse 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 pslist all the running containers
docker ps -alist all the running containers as well as stopped containers
docker exec -it <container-name> shopen's shell inside the container
docker logs -f <container-name>fetch and follows the logs of the container
docker container statsView resource usage stats

Some Advanced Commands -

Docker Commands

Use case

docker context

used to setup context for local machine or remote machine

docker cp <source> <container-ID>:<destination path>

used to copy file from host machine to existing container

docker system df

shows all the disk usage of the container,images,local volume

docker system prune

removes all unused data using disk space

Thanks for reading <3

10
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.