User Tools

Site Tools


ubuntu:docker:remove_a_container

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ubuntu:docker:remove_a_container [2019/11/27 01:12] – created peterubuntu: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 
-</code> 
- 
- 
-To remove the containers: 
- 
-<code bash> 
-docker rm ID_or_Name ID_or_Name 
-</code> 
- 
----- 
- 
-===== 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 
-</code> 
- 
----- 
- 
-===== 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 review the list of exited containers, use the **-f** flag to filter based on status.  When you've verified you want to remove those containers, using **-q** to pass the IDs to the **docker rm** command. 
- 
-To list the containers: 
- 
-<code bash> 
-docker ps -a -f status=exited 
-</code> 
- 
- 
-To remove the containers: 
- 
-<code bash> 
-docker rm $(docker ps -a -f status=exited -q) 
-</code> 
- 
----- 
- 
-===== Remove containers using more than one filter ===== 
- 
-Docker filters can be combined by repeating the filter flag with an additional value.  This results in a list of containers that meet either condition.  For example, if you want to delete all containers marked as either Created (a state which can result when you run a container with an invalid command) or Exited, you can use two filters: 
- 
-To list the containers: 
- 
-<code bash> 
-docker ps -a -f status=exited -f status=created 
-</code> 
- 
- 
-To remove the containers: 
- 
-<code bash> 
-docker rm $(docker ps -a -f status=exited -f status=created -q) 
-</code> 
- 
----- 
- 
-===== 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**.  Note that these utilities are not supplied by Docker and not necessarily available on all systems: 
- 
-To list the containers: 
- 
-<code bash> 
-docker ps -a |  grep "pattern” 
-</code> 
- 
- 
-To remove the containers: 
- 
-<code bash> 
-docker ps -a | grep "pattern" | awk '{print $3}' | xargs docker rmi 
-</code> 
- 
----- 
- 
-===== Stop and remove all containers ===== 
- 
-You can review the containers on your system with **docker ps**.  Adding the **-a** flag will show all containers.  When you're sure you want to delete them, you can add the **-q** flag to supply the IDs to the **docker stop** and **docker rm** commands: 
- 
-To list the containers: 
- 
-<code bash> 
-docker ps -a 
-</code> 
- 
- 
-To remove the containers: 
- 
-<code bash> 
-docker stop $(docker ps -a -q) 
-docker rm $(docker ps -a -q) 
-</code> 
- 
  
ubuntu/docker/remove_a_container.1574817177.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki