[Memo] Commands used when using Docker (stop container, delete, delete image)

Introduction

Make a note of the commands to stop and delete the container and delete the image when using Docker by yourself.

Checking the running container

Use the command below to get the running container ID.

$ docker ps -q

You can get the container ID as shown below.

d75e0580aa81
d886772499bd

Stopping container while running

Use the command below to stop the running container. This time I'm going to stop the container ID d886772499bd.

$ docker stop d886772499bd

Delete container

Delete the container using the command below. This time I'm going to stop the container ID d886772499bd.

$ docker rm d886772499bd

Bulk deletion of containers

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.

Image confirmation

Use the command below to get the image ID.

$ docker images -q

You can get the image ID as shown below.

30557a29d5ab
746b819f315e

Delete image

Delete the image using the command below. This time I will stop the image ID 746b819f315e.

$ docker rmi 746b819f315e

Bulk delete images

You can delete the image at once by using the following command.

$ docker images -aq | xargs docker rmi

Recommended Posts

[Memo] Commands used when using Docker (stop container, delete, delete image)
[Docker] Start container, start bash in container, delete image
Delete unused docker image
Docker Frequently used commands
Summary of frequently used Docker commands
Introduction to Docker (1) Frequently used commands
Let's specify the version when using docker
Proxy server with squid using docker image
Quick build maven project using maven docker container
Image flew when updating Docker with WSL2
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
Point memo that was moss when building a docker container created by a colleague