Remove Container in Docker

In this tutorial, I will show you all how to remove a Container in Docker.

The first is the way to remove a Container.

To remove a Container in the Docker, the first thing you need to do is to determine the Container ID or Container Name of the Container, then use the following command to remove it:

For example, I currently have the following Containers in my Docker:

Remove Container in Docker

Now that I need to remove the Container with ID is 32e994044d46, we can use the following statement:

Result:

Remove Container in Docker

Now, if I check the existing Containers in my Docker, only three Containers as follows:

Remove Container in Docker

The second is that we will set it up when we exit a Container, it will be deleted automatically.

This way, when starting a Container with the statement:

then you should add another parameter -rm.

Completing the statement as follows:

To remove Containers with status exited, you can use a flag of -f to filter exited Containers by status, then use the docker rm command to remove them.

For example:

Remove Container in Docker

These are the Containers in my Docker with status = exited.

Now I will delete them as follows:

The -q parameter is used to print out the IDs of deleted Containers.

Result:

Remove Container in Docker

You can also use multiple -f flags to add more filters.

For example:

 

Add Comment