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. ubuntu环境配置eclipse+opencv

    blockquote { direction: ltr; color: rgb(0, 0, 0) } blockquote.western { font-family: "Liberatio ...

  2. Optional乱用Empty之No value present

    前言 看到好多文章都是推荐采用Optinal的,而经常我遇到问题的时候就想:如果设计成optional的话就不会忽略这种NullPointException错误了.然而,optional并不是想用就随 ...

  3. 程序员网站开发时应该注意的SEO问题

    一.链接的统一性 搜索引擎排名最主要的因素就是网站内容和链接,假如网站内部链接不一致,在很大程度上直接影响着网站在搜索引擎中的排名.例如彩票专营店导航栏中的“首页”链接,程序员在开发时可能会有以下几种 ...

  4. Cmder 软件中修改λ符号方法

    以前的版本 网上都有,我就不介绍了,  只介绍现在的 1. 打开Cmder软件安装位置 2. 打开vendor文件夹 profile.ps1文件 3. 找到第77行  Write-Host " ...

  5. 基于搜狗搜索的微信公众号爬虫实现(C#版本)

    Author: Hoyho Luo Email: luohaihao@gmail.com Source Url:http://here2say.me/11/ 转载请保留此出处 本文介绍基于搜狗的微信公 ...

  6. 使用svn与maven管理的项目导入Eclipse,但是与本地svn客户端关联不上?

    因为这个问题,导致我的项目导了删,删了导.现在终于弄明白了. 首先,需求场景是:    1.使用svn进行版本控制;    2.使用maven进行项目管理.    3.使用Tortoise svn将项 ...

  7. 根据Dockerfile创建docker dotnet coer 镜像

    那我们先来看看Dockerfile文件内容,注意这个文件是没后缀名的. #依赖原始的镜像,因为我们是要创建dotnet coer镜像,所以我就用了官方给的镜像[microsoft/dotnet:lat ...

  8. Linux命令-基本命令(1)

    1. ll dfdfdfd 2. vi dfffd

  9. Eratosthenes,筛法求素数

    //筛法求区间[0,n]的所有素数,v为素数表 //v[i]==0,i为素数 void f(int n) { int m=sqrt(n+0.5); memset(v,,sizeof(v)); ;i&l ...

  10. 从一个简单案例上手Spring MVC,同时分析Spring MVC面试问题

    很多公司都会用Spring MVC,而且初级程序员在面试时,一定会被问到这方面的问题,所以这里我们来通过一个简单的案例来分析Spring MVC,事实上,我们在培训中就用这个举例,很多零基础的程序员能 ...