This tutorial will explain some useful commands that you can use to remove Docker containers and keep your system organized.
Remove a Single Container
To remove a Docker container, you will need to stop the container if it is in the running state.
First, locate the ID of all containers via the following command:
Or
You should see a list of the IDs of all containers in the following output:
ebed89569170 nginx "/docker-entrypoint.…" 44 seconds ago Up 42 seconds 80/tcp gifted_snyder
0b5c6967b76f mariadb "docker-entrypoint.s…" 56 seconds ago Exited (1) 54 seconds ago suspicious_napier
8f53ea801780 wordpress "docker-entrypoint.s…" About a minute ago Up About a minute 80/tcp crazy_nobel
ae6cc9f3a1cf wordpress "docker-entrypoint.s…" 2 minutes ago Exited (0) 2 minutes ago lucid_wozniak
Now, run the following command by specifying the ID of the container that you want to stop:
Or
Once your container is stopped, run the following command to remove the container:
Remove Multiple Containers
You can also remove multiple containers at a time using a single command.
To remove multiple containers, run the following command, along with the IDs of the containers that you want to remove:
Remove All Containers
Docker also allows you to remove all containers on your system at once using a single command. But you must first stop all running containers on your system.
First, stop all the containers from running with the following command:
You should see the following output:
0a51419388e2
0b5c6967b76f
8f53ea801780
ae6cc9f3a1cf
Next, make sure that all the containers are stopped using the following command:
You should see the following output if all the containers have been stopped:
Next, remove all the containers by running the following command:
Verify whether all containers are deleted using the following command:
You should see the following output:
Conclusion
In the above guide, you learned how to remove Docker containers. I hope this will help you to perform day-to-day tasks on your system.
from Linux Hint https://ift.tt/2Fg04tF
0 Comments