ubuntu:docker:remove_a_container
Differences
This shows you the differences between two versions of the page.
ubuntu:docker:remove_a_container [2019/11/27 01:12] – created peter | ubuntu:docker:remove_a_container [2020/04/15 22:04] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Docker - Remove a container ====== | ||
- | |||
- | ===== Remove one or more specific containers ===== | ||
- | |||
- | Use the **docker ps** command with the **-a** flag to locate the name or ID of the containers you want to remove: | ||
- | |||
- | To list the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a | ||
- | </ | ||
- | |||
- | |||
- | To remove the containers: | ||
- | |||
- | <code bash> | ||
- | docker rm ID_or_Name ID_or_Name | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Remove a container upon exit ===== | ||
- | |||
- | If you know when you're creating a container that you won't want to keep it around once you're done, you can run **docker run --rm** to automatically delete it when it exits. | ||
- | |||
- | Run and Remove: | ||
- | |||
- | <code bash> | ||
- | docker run --rm image_name | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Remove all exited containers ===== | ||
- | |||
- | You can locate containers using **docker ps -a** and filter them by their status: created, restarting, running, paused, or exited. | ||
- | |||
- | To list the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a -f status=exited | ||
- | </ | ||
- | |||
- | |||
- | To remove the containers: | ||
- | |||
- | <code bash> | ||
- | docker rm $(docker ps -a -f status=exited -q) | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Remove containers using more than one filter ===== | ||
- | |||
- | Docker filters can be combined by repeating the filter flag with an additional value. | ||
- | |||
- | To list the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a -f status=exited -f status=created | ||
- | </ | ||
- | |||
- | |||
- | To remove the containers: | ||
- | |||
- | <code bash> | ||
- | docker rm $(docker ps -a -f status=exited -f status=created -q) | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Remove containers according to a pattern ===== | ||
- | |||
- | You can find all the containers that match a pattern using a combination of **docker ps** and grep. When you're satisfied that you have the list you want to delete, you can use awk and xargs to supply the ID to **docker rmi**. | ||
- | |||
- | To list the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a | grep " | ||
- | </ | ||
- | |||
- | |||
- | To remove the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a | grep " | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Stop and remove all containers ===== | ||
- | |||
- | You can review the containers on your system with **docker ps**. Adding the **-a** flag will show all containers. | ||
- | |||
- | To list the containers: | ||
- | |||
- | <code bash> | ||
- | docker ps -a | ||
- | </ | ||
- | |||
- | |||
- | To remove the containers: | ||
- | |||
- | <code bash> | ||
- | docker stop $(docker ps -a -q) | ||
- | docker rm $(docker ps -a -q) | ||
- | </ | ||
- | |||
ubuntu/docker/remove_a_container.1574817177.txt.gz · Last modified: 2020/07/15 09:30 (external edit)