Docker basic commands

Docker creates lightweight unique virtual machine, called containers, on your machine. These containers differ from the tradition VM like VirtualBox in a way that all containers shares the same host operating system instead of each virtual machine having it’s own operating system.

A container is running instance of docker image.

Task Command
List all containers docker ps -a
List all containers’ ID docker ps -a -q
List all active containers’ name docker inspect -f $(docker ps -q)
List all docker images on current machine docker images
List all docker images’ ID docker images -q
Delete all docker images docker rmi $(docker images -q)
Delete all docker containers docker rm $(docker ps -a -q)
List all docker volumes docker volume ls
Delete all dangling volumes docker volume rm $(docker volume ls -f dangling=true -q)
Show docker stats with Container names instead of ID docker stats $(docker ps –format=)
Copy all files in src directory to dest directory docker cp /Users/host/src/. cont1:/home/container/dest
Create new src directory in dest directory docker cp /Users/host/src cont1:/home/container/dest
Delete all empty directories find . -type d -depth -print| xargs rmdir
find . -type d -empty | xargs rmdir