I’ve been playing around a lot with docker. It’s awesome, and it creates a whole new world of possibilities, and I’m constantly coming up with new ideas of where it could be useful.

After playing with docker for about a week on my development server, I logged in to find that my disk was completely full. I guess after dynamically spinning up dozens of containers, and building a bunch of projects with Dockerfiles I had accumulated quite a few stopped containers and untagged images. I suspect the build process to be the biggest contributor to this, as each step in your dockerfile creates a new container, which serves as the base for the next step. This is usfeul because it can cache the containers and speed up builds, but it does consume a bit of space.

I was not able to find any built-in commands for clearing stopped containers and untagged images, so I was able to put together a couple commands.

Remove all stopped containers.

docker rm $(docker ps -a -q)

This will remove all stopped containers by getting a list of all containers with docker ps -a -q and passing their ids to docker rm. This should not remove any running containers, and it will tell you it can’t remove a running image.

Remove all untagged images

In the process of running docker I had accumulated several images that are not tagged. To remove these I use this command:

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

This works by using rmi with a list of image ids. To get the image ids we call docker images then pipe it to grep "^<none>". The grep will filter it down to only lines with the value “<none>” in the repository column. Then to extract the id out of the third column we pipe it to awk "{print $3}" which will print the third column of each line passed to it.

After running these two commands I recovered 15G of space. There may be more I could do to recover more space, my docker graph directory still is over 5G, but for now this works.

http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html

Remove Untagged Images From Docker的更多相关文章

  1. [Angular CLI] Build application without remove dist folder for Docker Volume

    When we develop the Angular app inside Docker container, we can simulate Production envioment by bui ...

  2. how to remove untagged / none images

    docker rmi $(docker images -a| grep "^<none>" | awk '{print $"3"}')

  3. Centos6.5下docker 环境搭建

    一.运行docker Linux内核版本需要在3.8以上,针对centos6.5 内核为2.6的系统需要先升级内核.不然会特别卡,退出容器. 在yum的ELRepo源中,有mainline(3.13. ...

  4. docker好文收藏

    深入浅出Docker(一):Docker核心技术预览 2. 核心技术预览 Docker核心是一个操作系统级虚拟化方法, 理解起来可能并不像VM那样直观.我们从虚拟化方法的四个方面:隔离性.可配额/可度 ...

  5. docker offical docs:Working with Docker Images

    Working with Docker Images ##orignal is always the best In the introduction we've discovered that Do ...

  6. docker operation method note

    docker stop script #!/bin/bash CID_LIST=$(docker ps -q | xargs)if [ "$CID_LIST" = "&q ...

  7. Docker 基础 (一)

    为什么要使用 Docker? 作为一种新兴的虚拟化方式,Docker 跟传统的虚拟化方式相比具有众多的优势.首先,Docker 容器的启动可以在秒级实现,这相比传统的虚拟机方式要快得多. 其次,Doc ...

  8. docker rmi命令-删除image

    rmi 删除image Usage: docker rmi IMAGE [IMAGE...]Remove one or more images -f,--force=falseForce remova ...

  9. Centos7 docker 常用指令

    Docker 运行在 CentOS 7 上,要求系统为64位.系统内核版本为 3.10 以上 一.docker的安装及卸载 1.查看当前系统内核版本: [root@docker ~]# uname - ...

随机推荐

  1. express简介

    Express 是一个简洁而灵活的 node.js Web应用框架, 提供了一系列强大特性帮助你创建各种 Web 应用,和丰富的 HTTP 工具. 使用 Express 可以快速地搭建一个完整功能的网 ...

  2. 通过js修改网页内容

    js可以通过文本所在标签的id获取该标签对象,然后修改其内容,如: document.getElementById('标签id').innerHTML = '要修改的文本内容'; 该方法可以在要修改的 ...

  3. 解决Jqyery的Trigger事件中两个按钮相互触发至死循环问题

    今天做项目,其中有个功能需要两个图表的联动,用到两个按钮,这两个按钮分别控制两个图表,第一次直接在btn1的单击事件中使用了$("btn2").trigger("clic ...

  4. Shell一个文件并等待完成

    Option Explicit Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAcce ...

  5. PHP windowns安装扩展包

    1.  php_msgpack.dll php.ini 添加  extension=php_msgpack.dll 下载dll: http://pecl.php.net/package/msgpack ...

  6. C# 通配符转正则

    可以使用下面代码把通配符转正则字符串 public static class WildcardRegexString { /// <summary> /// 通配符转正则 /// < ...

  7. win10 uwp 上传Nuget 让别人用我们的库

    Nuget 我们的开发经常使用别人的dll,那么我们需要每次都从网上下载,然后复制到我们的项目, 而不知道我们的dll是否安全? 当我们的库更新的时候,我们又需要从网上搜索,这样不好,于是我们就用Nu ...

  8. Android基础知识03—Activity的基本用法

    ------Activity 活动------ 活动 Activity 是一种包含用户界面的组件,即一个界面就是一个活动 创建活动的过程: >> 创建一个类,继承自Activity类,并且 ...

  9. 起名字好难啊!(初识Django)

    这次我们将实现一个简单的登录注册功能,并吧相应的数据写入数据库: 做这件事之前我已经在数据库中新建了两张表(当然一张表也可以用,先注册后登录嘛···)    两张结构很简单的数据表:↓ 接下来就该干正 ...

  10. JavaScript函数之作用域 / 作用链域 / 预解析

    关于作用域和作用链域的问题,很多文章讲的都很详细,本文属于摘录自己觉得对自己有价值的部分,留由后用,仅供参考,需要查看详细信息请点击我给出的原文链接查看原文件 做一个有爱的搬运工~~ -------- ...