Removing Docker Containers and Images
Removing Docker Containers and Images
In a recent post aboutDocker, we looked into some things that differentiate Docker containers from Virtual Machines. I also gave a brief example of creating your first Docker image. If any of that piqued your interest and you started just trying stuff, you end up like I did with a BUNCH of images now cluttering up your machine and wondering how in the world can I clean this up? Here are a few commands that will get your Docker environment under control.
List Docker Images
- docker images
Docker provides a number of simple options to allow the admin to manage the environment. Docker images for examples lets us see all the docker images on the machine.
Last login: Fri Apr 14 17:16:30 on ttys001
Danny: > docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oraclelinux latest 62e4327762a5 2 days ago 225 MB
pythonslim latest 2f61057fee22 3 weeks ago 318 MB
<none> <none> c133f715830e 3 weeks ago 310 MB
sqlslim latest 6cab4fd15c1d 3 weeks ago 348 MB
oels latest 9546896416f7 3 weeks ago 114 MB
sqlcl latest 980f85fc564e 4 weeks ago 463 MB
oraclelinux 7-slim f005b5220b05 7 weeks ago 114 MB
Wouldn’t you love to clear some of that space up?
Remove Docker Images
- docker rmi <image id>
Docker provides rmi option to delete images. Let go ahead and put this one to work and remove the first image
Danny: > docker rmi 62e4327762a5
Error response from daemon: conflict: unable to delete 62e4327762a5 (must be forced)
- image is being used by stopped container be2d81554955
Well what happened? Look closely, this image is being used by a stopped container. Alright so now we need to go find that container. On to our next command to get rid of the Docker Container.
Remove Docker Containers
- docker rm <container id>
Again, Docker provides an option, rm that allows us to delete any docker containers from our local system. Before we can run this in general, we need to find out Container IDs. In the situation above, we actually have it, but let’s user Docker to find these ids for us with the ps option and the -a parameter so we can see all the Docker Containers even if they are not running.
- docker ps -a
Danny: > docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f9d34aee084 sqlslim "/bin/bash" 4 minutes ago Exited (0) 4 minutes ago xenodochial_darwin
e27743499f8d sqlslim "/bin/bash" 4 minutes ago Exited (0) 4 minutes ago epic_boyd
63b123e4f50c oraclelinux "/bin/bash" 24 hours ago Exited (0) 24 hours ago amazing_wilson
be2d81554955 oraclelinux "/bin/bash" 24 hours ago Exited (0) 24 hours ago elated_elion
9e701197cddc pythonslim "/bin/bash" 3 weeks ago Exited (0) 3 weeks ago keen_ramanujan
58726602aa40 c133f715830e "/bin/bash" 3 weeks ago Exited (0) 3 weeks ago zealous_spence
5a04b41413ce sqlslim "sql dbryant/eyeam..." 3 weeks ago Exited (0) 3 weeks ago sharp_lichterman
b7c7569d21fc sqlslim "sql dbryant/eyeam..." 3 weeks ago Exited (1) 3 weeks ago naughty_carson
f852641bf275 sqlslim "sql sys/eyeamd1@1..." 3 weeks ago Exited (1) 3 weeks ago kind_kare
6e3120482e96 sqlslim "sql sys/eyeamd1@1..." 3 weeks ago Exited (1) 3 weeks ago blissful_austin
47efed596e8b sqlslim "sql sys@192.168.5..." 3 weeks ago Exited (1) 3 weeks ago serene_hamilton
5b608a95492b sqlslim "sql dbryant/eyeam..." 3 weeks ago Exited (1) 3 weeks ago friendly_hodgkin
bdabab59992b sqlslim "sql dbryant/eyeam..." 3 weeks ago Exited (1) 3 weeks ago gifted_albattani
566da1f2d8a3 99ad69730de1 "/bin/sh -c 'unzip..." 3 weeks ago Exited (127) 3 weeks ago loving_jones
Now we have everything we need to get rid of those container and images. By the way, did you notice this guy here (be2d81554955) about 4 rows down? That’s your offending Container keeping you from delete that image.
Stop & Remove All Docker Containers
I’m going to nuclear and stop and delete everything with a few “shortcuts.” Using the examples above, you can stop and delete individual container by simply entering the container id after the docker option. Here let’s blow them all away:
- docker stop $(docker ps -a -q)
Here I am nesting two commands that you have already seen. The docker stop command with the docker ps -a -q (the -q is for quiet — only show IDs). This in essence passes a list of Docker Container IDs to the docker stop command resulting in the stoppage of all Docker Containers.
Danny: > docker stop $(docker ps -a -q)
9f9d34aee084
e27743499f8d
63b123e4f50c
be2d81554955
9e701197cddc
58726602aa40
5a04b41413ce
b7c7569d21fc
f852641bf275
6e3120482e96
47efed596e8b
5b608a95492b
bdabab59992b
566da1f2d8a3
Now that the Containers have been stopped, I’m going to nest another command with the docker ps -a -q command to remove/delete the Container
Danny: > docker rm $(docker ps-a-q)
9f9d34aee084
e27743499f8d
63b123e4f50c
be2d81554955
9e701197cddc
58726602aa40
5a04b41413ce
b7c7569d21fc
f852641bf275
6e3120482e96
47efed596e8b
5b608a95492b
bdabab59992b
566da1f2d8a3 Danny: > docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Now you can see that all the Container are gone and move on with removing the Docker Images.
First re-issue the docker images command to get a look at the images that are currently out there,
Danny: > docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oraclelinux latest 62e4327762a5 2 days ago 225 MB
pythonslim latest 2f61057fee22 3 weeks ago 318 MB
<none> <none> c133f715830e 3 weeks ago 310 MB
sqlslim latest 6cab4fd15c1d 3 weeks ago 348 MB
oels latest 9546896416f7 3 weeks ago 114 MB
sqlcl latest 980f85fc564e 4 weeks ago 463 MB
oraclelinux 7-slim f005b5220b05 7 weeks ago 114 MB
and make sure that we take care of that initial attempt that failed.
Danny: > dockerrmi 62e4327762a5
Untagged: oraclelinux:latest
Untagged: oraclelinux@sha256:39470a3bde74c099eefe0656635718c31d199e27cdc026742257c0d445f7f7e9
Deleted: sha256:62e4327762a51cacfcca77b032e2e5adb73bdc41836ed1180d0fe8f7cebba932
Deleted: sha256:40c24f62a02f157ab14f45407e9dd284b05299b9d90c1fb899f716e42f2bd912
As you can see here, the image was successfully deleted. Now for the nuclear option! Getting rid of them all with, and you guessed it, another nested option.
- docker rmi $(docker images -q)
Danny: > docker rmi $(docker images-q)
Untagged: pythonslim:latest
Deleted: sha256:2f61057fee22ed529119aba221b61afce076a05b81dd374320044a2d01f932a7
Deleted: sha256:8061aead716665ce0746794932d9f96f489bc5ed73b58789837196e92c082e20
Deleted: sha256:ff49d613d58d807cd87c589498a6eac39d7700f0595c6a1a727278c6a9af1243
Deleted: sha256:c133f715830e6ddf0c861675107015edbffe6f42fab7c23d9a1be5b84c9770dd
Deleted: sha256:68331ccc086054bfb451af10b330d12702b147c3e5628a6c3d8f3ef96a56ad60
Deleted: sha256:87e67f661cf0f66f4c48b4025445ec6ea88d8df5c008930a5fbf0bf43c312e57
Untagged: sqlslim:latest
Deleted: sha256:6cab4fd15c1d5eb9d45d1e5e22df91ec914571eaaf2cc679d6fbdc16610ba246
Deleted: sha256:5d0a16807c54d5eaa8485843efe7c8ac8a01fc107c66bc6d3c845ab1b83f291c
Deleted: sha256:3b73082d9f20f368d1bd62a10318d2300aecba7590aff9d5e0be561bea2bc587
Deleted: sha256:99ad69730de183ba793a685e3684c4f8c7618cf6d5a083fe3146b8fdab03aa8f
Deleted: sha256:ec69f880eb5d70d215196fc0754ee3658886c3ae5b88b5cd0b45dfac10c47770
Untagged: oels:latest
Deleted: sha256:9546896416f76c089644165d018bb0146dd58f2800edced807477093f898e42f
Deleted: sha256:f2af978d2706d37570523170bcfe2c0befee0aafcdf98f7ed71df7419fed8b74
Deleted: sha256:d3ed559d48454ec158117b6e9f907ef87db26071e7c8f19515150db8d8f461a6
Untagged: sqlcl:latest
Deleted: sha256:980f85fc564ee7ae9f224ad3000aef33714cebb6826e54f49ef7efdb87d4be76
Deleted: sha256:bbf0c41ed3632412acd3fa68799b68013069d519ea38376ba174bc753c26db83
Deleted: sha256:26086900ad8f2e62172ef8ee3e5ce2a0e3f6a6ebbcd038d99ff0f65fe6dff285
Deleted: sha256:ef746b0f221637bc6e833331045d3e0c3d5e9bca76dad0ac74dddca48b934ca4
Deleted: sha256:488bdfc5ae796dc06e374d0d95a60ab91f39900bc86bc3343e689e5ea865f119
Deleted: sha256:5a42e075a32bd55aa2131239a235dbaf95426a8333ef8f6ce16ba8a3af1ba3c2
Deleted: sha256:d423508a08c8c0039dd3b4baef9e8964e0925ef57c18647ce30b655a68f8848d
Untagged: oraclelinux:7-slim
Untagged: oraclelinux@sha256:f3a78afd456061bb897b9f2b54b568dec3973efccf2b086d602fabb94069fb6d
Deleted: sha256:f005b5220b05d380d279657c268e4024e72f4141fa070e515f81a9eab5157652
Deleted: sha256:dae53bfc95d17daa53043f78a411d88955bcbaa93f3feeb91e6eac044ad81052 Danny: > docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Danny: >
here we have it Container and Images are now removed from your machine. Simply run your docker build command(s) recreate your images and containers.
Enjoy!
Removing Docker Containers and Images的更多相关文章
- Understanding how uid and gid work in Docker containers
转自:https://medium.com/@mccode/understanding-how-uid-and-gid-work-in-docker-containers-c37a01d01cf Un ...
- Running Elixir in Docker Containers
转自:https://www.poeticoding.com/running-elixir-in-docker-containers/ One of the wonderful things abou ...
- docker log 批量删除报错: find: `/var/lib/docker/containers/': 没有那个文件或目录
问题描述: 服务器上面docker log太多,打算用之前写的批量清理shell脚本清理掉,但是发现报错. find: `/var/lib/docker/containers/': 没有那个文件或目录 ...
- [Docker] Run Short-Lived Docker Containers
Learn the benefits of running one-off, short-lived Docker containers. Short-Lived containers are use ...
- [Docker] Run, Stop and Remove Docker Containers
In this lesson, we'll find out the basics of running Docker containers. We'll go over how to downloa ...
- [Docker] Prune Old Unused Docker Containers and Images
In this lesson, we will look at docker container prune to remove old docker containers. We can also ...
- Configuring and Running Django + Celery in Docker Containers
Configuring and Running Django + Celery in Docker Containers Justyna Ilczuk Oct 25, 2016 0 Commen ...
- Docker目录/var/lib/docker/containers文件太大
Docker在不重建容器的情况下,日志文件默认会一直追加,时间一长会逐渐占满服务器的硬盘的空间,内存消耗也会一直增加,本篇来了解一些控制日志文件的方法. 查出占用磁盘较大的文件 Docker 的日志文 ...
- A workaround to change shared memory size for Docker containers in AWS ECS
Issue Because of not supporting to specify the following docker run parameter, containers in ECS can ...
随机推荐
- winform 之公共控件
Button 按钮 属性: (一).布局: 1.AutoSize:控件是否根据内容调整大小 2.Location:当前按钮位于界面位置 3.Dock:控件锁定到界面位置 -None:不锁定 4.Mar ...
- Spring.net介绍及MVC中应用
Spring.net两大核心内容: IOC(控制反转) 传统的面相对象思维模式是对象A依赖对象B,对象B的实例化和调用都在对象A中发生,一旦对象B中发生变化,对象A也要随之变化,这样使得程序间行程了紧 ...
- 字符串流stringReader
String info ="good good study day day up";StringReader stringReader = new StringReader(inf ...
- 用代码检查Windows程序的位数
方法就是通过读取程序文件的头部来判断,具体代码如下: #include <stdio.h> #include <windows.h> int CrnGetImageFileMa ...
- day04-完整性约束
完整性约束 关键字: not null 与 default unique primary auto_increment foreign key 1.介绍 约束条件与数据类型的宽度一样,都是可选参数作用 ...
- Xshell 公钥登入服务器
1:生成公钥 此时有test.pub文件 2:linux CentOS 7 配置 2.1 test.pub 存入/root/test.pub目录下面 2.2 确保authorized_keys文件内容 ...
- 塔式Server 服务器ESXI6.5安装
参考文献: https://www.cnblogs.com/yufusec/p/9181422.html 第一步: esxi6.5.ios文件的下载 第二步: 通过UltraISO软件 制作启动盘或光 ...
- AS3 - 对文件和目录的操作
1,写入到文件 1 2 3 4 5 var fileObj:File = File.documentsDirectory.resolvePath("hangge.txt"); va ...
- kafka config
Config parameters that influence the log retention time. log.roll.hours # how long to produce a new ...
- linux 协议栈tcp的rst报文中,seq的选取问题
之前在<深入理解并行编程>的群里,有个小米的兄弟问了一个问题,服务器A发包给服务器B,Seq是1,但是在未能收到服务器B的报文回复的情况下,发送了rst,但是rst报文中,对应的seq是1 ...