The following commands are the most used and basic docker commands.
docker pull <image-name> : downloads image from docker hub (if you do not specify the version tag it will download the latest)
docker images: lists docker images
docker image rm <image-name> : deletes docker image
You can delete multiple images like this:
docker image rm $(sudo docker images | grep <imagename>)
docker run <image-name>: creates a new container from the image and runs the container.
docker ps : list currently running containers
docker run -d <image-name> : Docker container runs in the background of your terminal. -d flag causes Docker to start the container in "detached" mode. A simple way to think of this is to think of -d as running the container in "the background," just like any other Unix process.
docker stop <container-id> : stops a container
docker start <container-id> : starts (runs) an existing container
sudo docker ps -a : shows all containers including the containers which are not running. Status tab tells us if container is up and running or not.
docker rm <container-id> : deletes a container with the specific container id
docker ps -aq: lists all containers id
docker rm $(docker ps -aq) : deletes all containers. You can not delete running containers. However you can use -f flag and delete all containers with force switch.
docker rm -f $(docker ps -aq)
You should always name your containers for simplicity. Otherwise the name will be made up automatically by docker engine such as focused_noyce or eager_darwin which does not make no sense to anyone.
Then I can use the name I gave to my container just like this