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.
d75e0580aa81
d886772499bd
Use the command below to stop the running container. This time I'm going to stop the container ID d886772499bd
.
$ docker stop d886772499bd
Delete the container using the command below. This time I'm going to stop the container ID d886772499bd
.
$ 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.
30557a29d5ab
746b819f315e
Delete the image using the command below. This time I will stop the image ID 746b819f315e
.
$ docker rmi 746b819f315e
You can delete the image at once by using the following command.
$ docker images -aq | xargs docker rmi
Recommended Posts