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 .Name $(docker ps -q)
List all docker images on current machine docker images
List all docker images ID docker images -q
List all docker volumes docker volume ls
Stop all containers docker stop $(docker ps -a -q)
Delete all dangling volumes docker volume rm $(docker volume ls -f dangling=true -q)
Delete all volumes docker volume rm $(docker volume ls -q)
Delete all docker containers docker rm $(docker ps -a -q)
Delete all dangling images docker rmi $(docker images -f dangling=true -q)
Delete all docker images docker rmi $(docker images -q)
Show docker stats with Container names instead of ID docker stats $(docker ps --format=.Names)
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
Create volume if not exists docker volume inspect service1-db \|\| docker volume create --name service1-db