Docker command cheatsheet

The reason for creating this cheat sheet is because a long time ago I was called for an interview and he asked me some basic command questions regarding docker and in reply, I said "I forget the actual command 😑" yeah you read it right I know it sounds not good so for the next time I make sure this won't happen again in my life that is why I wrote down below some basic commands that every docker user should know. Hope this cheat sheet is also helpfully for you.😀
To see all commands of docker 
Write down docker on the command line. You will see all the commands of docker in the image below.


Get the status of the docker daemon

  1. Docker information:- docker info

Create a container without  starting It

  1. Creates container:- docker create [image name]


Docker run commands 

  1. Run container:- docker run [image name]

  1. Run container with specified image version:- docker run [image name]:[version]

  2. Docker run in background/detach mode image :- docker run -d [image name]


Docker naming container

  1. Docker naming container:- docker run -it --name [container name] [image name] 

Docker renaming existing  container


  1. Docker renaming existing container :- docker rename [container name] [new container name]


Listing out running/stop containers, images, events of the container, history of images


  1. List all running containers:- docker ps

  2. List all running/stop containers:- docker ps -a

  3. Lst out most recently created images:-  docker images

  4. List all  images:-  docker image ls

  5. List real-time events from a container:-  docker events [container name]

  6. Check history  of images :-  docker history [option] [image]

  7. Show running processes in a container:- docker top [CONTAINER]

  8. List all networks:- docker network ls

Docker  start, stop, restart, pause, unpause, wait, kill, attach the container


  1. Stop docker container :- docker stop [container name/id]

  2. Start docker container :- docker start [container name/id]

  3. Restart docker container :- docker restart [container name/id]

  4. Pause docker container :- docker pause [container name/id]

  5. Unpause docker container :- docker unpause [container name/id]

  6. Wait docker container:- docker wait [container name/id]

  7. Kill docker container :- docker kill [container name/id]

  8. Attach docker container :- docker attach [container name/id]


Docker remove

  1. Remove  docker container :- docker rm [container name/id]

  2. Remove  docker image :- docker rmi [image name]

  3. Remove  all unused docker container:- docker container prune

  4. Remove  all unused docker images:- docker image prune 

  5. Remove all unused images as well as containers:- docker system prune 

  6. Remove one or more networks:- docker network rm [NETWORK]


Docker update

  1. Update the configuration of one or more containers:- docker update [CONTAINER]

Docker import

  1. Create an image from a tarball:- docker import [URL/FILE]

Docker commit

  1. Create an image from a container:- docker commit [CONTAINER] [NEW_IMAGE_NAME]

Docker load

  1. Load an image from a tar archive or stdin:- docker load [TAR_FILE/STDIN_FILE]

Docker pull

  1. Pull  docker image:- docker pull [image name]


Docker save

  1. Save an image to a tar archive, streamed to STDOUT with all parent layers, tags, and versions:- docker save [IMAGE] > [TAR_FILE]

Docker Mapping

  1. Docker port mapping :-  docker run -p  [base ip:container ip] [image name]

  2. Docker volume mapping :- docker run -v  [base dir:container dir] [image name]

  3. Show port (or specific) mapping for a container:- docker port [CONTAINER]



Docker run in interactive

  1. Docker run in an interactive way:- docker run -it [image name]


Docker inspect

  1. Docker find additional details of container :- docker inspect [container name/id]

  2. Show information on one or more networks:- docker network inspect [NETWORK]

Docker stats
  1. Show live resource usage statistics of containers:- docker stats [CONTAINER]

Docker logs

  1. Docker check logs of container:- docker logs  [container name/id]


Docker connect
  1. Connects a container to a network:- docker network connect [NETWORK] [CONTAINER]
  2. Disconnect a container from a network:- docker network disconnect [NETWORK] [CONTAINER]

Docker space
  1. Detailed disk usage:- docker system df
  2. Space used by each container, image and volume:- docker system df -v
  3. Space used by running containers:- docker ps -s
  4. Filter only >= 1GB :- docker system df -v | grep GB

Note:- These are some basic commands. I am not mentioning each and every command but if you are curious to know more docker commands you can click on the below link.

Comments

Popular posts from this blog

How to pass parameters in webhook?

Access and modify all the resources of our Wiki.js using WikiJS API

Fahrenheit to Celsius