Make a note of the commands to stop and delete the container and delete the image when using Docker by yourself.
Use the command below to get the running container ID.
$ docker ps -q
You can get the container ID as shown below.
Use the command below to stop the running container. This time I'm going to stop the container ID
$ docker stop d886772499bd
Delete the container using the command below. This time I'm going to stop the container ID
$ docker rm d886772499bd
You can use the command below to delete all containers at once even if there are many containers.
$ docker ps -aq | xargs docker rm
Please note that the above command will fail if there is a running container, so be sure to stop the running container before executing it.
Use the command below to get the image ID.
$ docker images -q
You can get the image ID as shown below.
Delete the image using the command below. This time I will stop the image ID
$ docker rmi 746b819f315e
You can delete the image at once by using the following command.
$ docker images -aq | xargs docker rmi